我的條形圖出現問題 - 錯誤欄僅出現在分組變量的列的角上,而不是以集中的方式顯示在列上。我使用的代碼是這樣的:將錯誤欄放在ggplot中的列中心的問題()
a <- data.frame (Cond = c("In", "In", "Out", "Out"),
Temp = c("Hot", "Cool", "Hot", "Cool"),
Score = c(.03, -.15, 0.84, 0.25),
SE = c(.02, .08, .14, .12))
a.bar <- ggplot (data = a, aes(x = Cond, y = Score, fill = Temp)) +
theme_bw() + theme(panel.grid = element_blank()) +
coord_cartesian (ylim = c(-0.5, 1)) +
geom_bar (aes(fill = Temp), stat = "identity", position = "dodge", width = .5) +
geom_errorbar (aes(ymin = Score - SE, ymax = Score + SE, group = Cond), position = position_dodge(.9), width = .08) +
labs(y = "Scores" , x = "Cond") +
scale_y_continuous (breaks = pretty_breaks(n=8)) +
theme(legend.title = element_blank()) +
theme(legend.position = "right")
替代代碼我已經盡力了,我不能讓任工作,包括增加「show.legend = FALSE」來geom_bar();添加「facet_wrap(〜Cond)」plot.a;並在ggplot(aes())中引入「fill = Temp」。 最接近的溶液是當我改變position_dodge()參數轉換爲:
geom_bar (aes(fill = Temp), stat = "identity", position = position_dodge(width = .5)) +
geom_errorbar (aes(ymin = Score - SE, ymax = Score + SE, group = Cond), position = position_dodge(.5), width = .08) +
(代碼的其餘部分保持不變)。這將誤差線移向了柱的中心,但也將柱移向了彼此,最終使它們重疊(見附圖)。
我非常感謝這方面的幫助。
謝謝!