clockplot<-function(x, y, h, m, r, border="black", col="lightblue",
col.hour="darkblue", col.min="red"){
#x and y are the coordinates of the clock
#h and m the hour (base 12) and minutes
# r the radius of the clock
t<-seq(0,2*pi,by=0.01)
x.c<-r*cos(t)+x
y.c<-r*sin(t)+y
t.h<-pi/2 - 2*pi*(h-m/60)/12
x.h<-0.5*r*cos(t.h)+x
y.h<-0.5*r*sin(t.h)+y
t.m<-pi/2 - 2*pi*m/60
x.m<-r*cos(t.m)+x
y.m<-r*sin(t.m)+y
polygon(x.c,y.c,col=col, border=border)
segments(x,y,x.h,y.h,col=col.hour)
segments(x,y,x.m,y.m,col=col.min)
}
myd <- data.frame (X = 1:5, Y = c(0.8, 0.6, 0.7, 0.75, 0.1),
clockd = c(12.05, 12.25, 12.45, 1.30, 2.1))
myd$hour<-myd$clockd%/%1
myd$min<-myd$clockd%%1 *100
plot(myd$X, myd$Y, type="l", asp=1)
apply(myd,1,function(x)clockplot(x[1],x[2],x[4],x[5], r=0.25))