时钟中的时间显示以及r中的xy散点图 [英] time display in clock with xy scatter plot in r
本文介绍了时钟中的时间显示以及r中的xy散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建以下类型的情节.但是不知道是否已经存在任何软件包,因为我找不到一个. 数据:
I would like to create the following type of plot. But do not know if there is any package already exists, as I could not find one. Data:
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))
时钟是时间12.05,是分钟的12点.我不知道在R中输入时间的合适单位.
clockd are time 12.05 is 12 Oclock past minutes. I do not know appropriate unit to enter time in R.
plot (myd$X, myd$Y)
红色和绿色箭头代表时钟中钟针的小时和最小位置.
The red and green arrow represents the hour and minitue position of clock arms in a clock.
推荐答案
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))
这篇关于时钟中的时间显示以及r中的xy散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文