2013-11-14 31 views
0

我有一個用格的xyplot生成的線條圖。它包含兩種測量的溫度類型,其中一種是平均值。因此,我想向這些點添加標準錯誤(t.tort)。在格線圖中分別添加誤差條?

Temperature Plot

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") 

我的數據幀的重要位如下:不幸的是,單獨執行該操作不使用(Hmisc)errbar ......這裏是我想出了工作至今:

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) 

我對此感到有點沮喪,所以任何建議都會被大大地塗抹。 非常感謝您的努力!

+0

你不能混合基礎和網格圖形。你環顧四周嗎? http://stackoverflow.com/questions/2381618/how-to-draw-a-chart-with-sorted-horizo​​ntal-error-bars-sorted-barcharts-with-err –

回答

0

試試這個

您的數據:

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", ...) 
    } 
) 

在這裏你去:enter image description here

可以使用panel.arrows()代替段,如果你真的想把這些小小的帽子放在你的錯誤欄上。

+0

親愛的麻雀,非常感謝你爲此 - 你是我的英雄! =)我之前玩過面板,但無法使用它... – LeoTor