【问题标题】:Phase plane plotting in R using fda package phaseplanePlot command使用 fda 包 phaseplanePlot 命令在 R 中绘制相平面
【发布时间】:2016-07-13 05:07:44
【问题描述】:

所以我试图计算一些功能数据的相平面图,它是根据时间测量的,所以我希望图上的标签每 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)

这会产生以下情节,没有标签?

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

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

我不知道如何解决它??

【问题讨论】:

  • 与您的问题无关,但我认为您不需要致电attach(alldata)(实际上大部分时间没有人需要attach...)。用外行的术语快速解释attach(obj) 函数的作用:它只获取obj 中的所有变量(可以是列表或data.frame 或环境)并将它们复制到全局环境中。所以如果obj包含一个名为foo的变量(或列),除了调用obj$fooattach(obj)之后,也可以直接使用foo
  • 关于您的问题,我们需要一个可重现的示例:请参阅 this post 了解一些技巧以使您的问题可重现。

标签: r plot functional-programming labels


【解决方案1】:

无需将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

那么,

【讨论】:

    猜你喜欢
    • 2020-12-20
    • 2021-12-08
    • 2020-02-04
    • 1970-01-01
    • 2020-12-23
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多