使用fda package phaseplanePlot命令在R中绘制相平面

时间:2016-03-25 12:32:26

标签: r plot functional-programming labels

所以我试图计算一些功能数据的相平面图,它是根据时间测量的,所以我希望图上的标签每12小时标记一次。

attach(alldata)

#identify the time measure form the data, and make a vector
tdata<-data.matrix(alldata[,1:1])

timev<-as.vector(tdata)

#identify the control group
control<-data.matrix(alldata[,2:25])

#create basis and smooth and create functional object
basis17<-create.fourier.basis(rangeval=c(0,5.24677083333333), nbasis=17)

csbasis17<-smooth.basis(argvals=tdata,control,basis17)

controlfd<-fd(coef(csbasis17),basis17) 

#creaste list of points whre i was labels to go and name them 

th<-list("12 hours"=timev[1:1],"24 hours"=timev[15:15],"36 hours"=timev[29:29],"48 hours"=timev[43:43],
         "60 hours"=timev[50:50], "72 hours"=timev[57:57], "84 hours"=timev[71:71],
         "96 hours"=timev[85:85] ,"108 hours"=timev[100:100],"120 hours"=timev[114:114], "136 hours"=timev[128:128])
#crerate list of 2 containing the points i want plotted and the names
ws<- list(th,labels(th))

#phase plane plot command 
phaseplanePlot(timev,controlfd,Lfdobj1=1, Lfdobj2=2,
               lty=c("longdash", "solid"),
               labels=ws)

这会生成以下图,没有标签?

enter image description here

这就是错误栏中出现的内容

Error in text.default(D1., D2., labels$labels) : 
  no coordinates were supplied

我无法弄清楚如何解决它?

1 个答案:

答案 0 :(得分:0)

无需将th放入列表中。由于您的示例不可复制,因此请假设长度为1:100,即曲线的前100个评估点,我们想在数据的原点"O",中间"M"和末尾"E"中绘制标签。然后,应按如下所示填充label参数:

arg <- 1:100

phaseplanePlot(timev,controlfd, Lfdobj1 = 1, Lfdobj2 = 2,
               lty = c("longdash", "solid"),
               label = list(evalarg = seq(arg[1], max(arg), length=3), 
                            labels = c("O","M","E"))

在这里

seq(arg[1], max(arg), length=3) 
[1]   1.0  50.5 100.0

然后, enter image description here