在GGPLOT2我嘗試,我只是不能出於某種原因一件簡單的事情平均分。我調整了數據框中的平均值和SE,並想繪製平均值,誤差線,然後用平均值連接平均值。下面的代碼和錯誤(它除了一切手段與geom_line
(與RCookbook工作連接:連接的誤差條
library(ggplot2)
#data set
data1 <- structure(list(group = structure(1:3, .Label = c("1", "2", "3"
), class = "factor"), estimate = c(55.7466654122763, 65.0480954172939,
61.9552391704298), SE = c(2.33944612149257, 2.33243565412438,
2.33754952927041), t.ratio = c(23.8290016171476, 27.8884844271143,
26.5043535525714)), .Names = c("group", "estimate", "SE", "t.ratio"
), row.names = c(NA, 3L), class = "data.frame")
#the attempted plot
pd <- position_dodge(.1)
ggplot(data1, aes(x=group, y=estimate, group=group)) +
geom_errorbar(aes(ymin=estimate-SE, ymax=estimate+SE),
colour="black", width=.1, position=pd) +
geom_line(data=data1, aes(x=group, y=estimate)) +
geom_point(position=pd, size=4)
錯誤:
ymax not defined: adjusting position using y instead
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
謝謝MNEL。這種情況下的團體恰好可以解決問題,但如果他們是A組,B組和C組呢?此外,我知道我沒有重新應用數據geom_line但呼籲瘋狂的想法:) –
可能有人解釋爲什麼我需要轉換爲數字或使用組=「所有」招的理由絕望的措施設置? –
工作良好---因爲'R'代碼因素的方式 – mnel