我正在嘗試使用 x 中條件 1 和 2 的條形圖繪制條形圖,填充 V2 的兩個級別,V3 對應于 y 中的計數。V3 對應于平均值,sds 對應于標準偏差。
df <- data.frame(V3 = c(0.87,0.78,0.9, 0.65),
V2 = c("A","B","C","D"),
V1 = c("OT","OT","PL","PL"),
sd = c(0.3,0.4, 0.2, 0.1))
ggplot(df, aes(x=V1,y=V3, fill = V2))
geom_bar(stat = "identity", width = 0.2, position = "dodge")
ylim(0,1)
geom_errorbar(aes(ymin=V3-sd, ymax=V3 sd), width=.2)
這是發生的事情:

如何使用誤差線解決此問題?而且,更改條形的顏色?當我添加標簽時它也沒有做任何事情......
labs(x = "legendX", y = "legendY")
uj5u.com熱心網友回復:
您需要在 geom_errorbar 內添加 position = position_dodge() 。此外,ylim 削減了超出限制的值,并且幾個 ymax > 1,因此它們從圖中消失。添加了一些漂亮的顏色 NEJM 風格。
ggplot(df, aes(x=V1,y=V3, fill = V2))
geom_bar(stat = "identity", width = 0.2, position = "dodge")
# ylim(0,1)
geom_errorbar(aes(ymin=V3-sd, ymax=V3 sd), width=.2, position = position_dodge())
scale_fill_manual(values=c("#c7533b", "#5b86c3", "#9fc66d", "#e39e3e"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/360785.html
