0

我有一个用 lattice 的 xyplot 生成的线图。它包含两种测量的温度,其中之一是平均值。因此,我想为这些点添加标准错误(t.tort)。不幸的是,使用 (Hmisc)errbar 单独执行此操作不起作用......这是我迄今为止提出的:

温度图

xyplot(mean.tort+t.ws~DateTime, pre, type=c("a", "p"), col=c("red", "blue"),
   main="Pre-Translocation",
   xlab=list(label="Date and Time", cex=1), 
   ylab=list(label="Temperature (°C)", cex=1),
   scales = list(tck = c(1, 0),
                 x=list(cex=0.8, rot=45, tick.number=40),
                 y=list(cex=0.8, tick.number=8, limits=c(29,43))),
   key=list(text=list(c("Tortoise","Ambient")), lines=list(col=c("red", "blue"),type="l"), corner=c(0.5,0.92)))
errbar(x=pre$DateTime, y=pre$mean.tort, yplus=pre$mean.tort+pre$se.tort,yminus=pre$mean.tort-pre$se.tort,
   add=T, col="red")

我的数据帧的重要位如下:

pre$DateTime<-c(as.POSIXct("2013-01-27 09:00:00" "2013-01-27 10:00:00" "2013-01-27 11:00:00" "2013-01-27 12:00:00" "2013-01-27 13:00:00")
pre$t.ws<-c(32.7, 35.5, 37.1, 37.6, 38.7)
pre$mean.tort<-c(32.4, 34.9, 35.1, 36.8, 37.7)
pre$se.tort<-c(0.825, 0.84, 0.21, 0.228, 0.28)

我对此感到有点沮丧,所以任何建议都会非常感激。非常感谢您提前付出的努力!

4

1 回答 1

1

尝试这个

您的数据:

pre = data.frame(DateTime = as.POSIXct(c("2013-01-27 09:00:00", "2013-01-27 10:00:00", 
                                     "2013-01-27 11:00:00", "2013-01-27 12:00:00", 
                                     "2013-01-27 13:00:00")),
            t.ws = c(32.7, 35.5, 37.1, 37.6, 38.7),
            mean.tort = c(32.4, 34.9, 35.1, 36.8, 37.7),
            se.tort = c(0.825, 0.84, 0.21, 0.228, 0.28))

剧情:

require(lattice)

xyplot(mean.tort+t.ws~DateTime, pre,
   main="Pre-Translocation",
   xlab=list(label="Date and Time"), 
   ylab=list(label="Temperature (°C)"),
   scales = list(tck = c(1, 0),
                 x=list(cex=0.8, rot=45, tick.number=40),
                 y=list(cex=0.8, tick.number=8, limits=c(29,43))),
   key=list(text=list(c("Tortoise","Ambient")), 
            lines=list(col=c("red", "blue"), 
                       type="l"), corner=c(0.5,0.92)),
   lx = pre$mean.tort - pre$se.tort, ux = pre$mean.tort + pre$se.tort,
   panel = function (x,y, lx, ux,  ...){
     panel.xyplot(x,y, type = "b", col=c("red", "blue"), ...)
     panel.segments(x0 = x, x1 = x, y0 = lx, y1 = ux, col = "red", ...)
   }
)

干得好:在此处输入图像描述

panel.arrows()如果你真的想把那些小“帽子”放在你的误差线上,你可以使用而不是分段。

于 2013-11-14T18:17:08.387 回答