2016-10-22 136 views
0

我已經使用ggplot從數據I轉化爲手段,代碼圖表:添加誤差線GGPLOT2

我想知道是否有無論如何,我可以添加誤差條該圖形。我知道我必須轉換數據以獲得更多摘要,但不知道如何繼續。試圖單獨做每列,但不能從它做出圖表。像這樣:

Temperature <- ddply(shlf, c("Location"), summarise, 
         N = length(temp), 
         mean.temp = mean(temp), 
         sd = sd(temp), 
         se = sd/sqrt(N)) 

任何幫助表示讚賞。

+0

請使用'dput(means)',這樣每個人都可以擁有確切的'data.frame'而不必按編號複製它(或者發明假數據)。 –

回答

2

你快到了。這是基於seTemperature數據提供:

means$upper = Temperature$mean.temp + Temperature$se 
means$lower = Temperature$mean.temp - Temperature$se 

ggplot(means, aes(x = temp, 
        y = Triconia, 
        color = Location)) + 
    geom_point(size = 5.0) + 
    geom_errorbarh(aes(xmin = upper, xmax = lower)) 

Errorbar作爲一個單獨的geom進來不同口味:geom_errorbar是垂直和geom_errorbarh是水平的;還有諸如geom_crossbargeom_pointrange等之類的東西。請參閱?geom_errorbar以獲得幫助以及所有這些示例的一些示例。

+0

這對我有用。 –