2
最近我學會了使用stat_summary像下面errorbars柱狀圖。GGPLOT2條形圖與幾個分類變量與同級別
library(ggplot2)
posn.d <- position_dodge(1.82)
ggplot(mtcars, aes(x=cyl, y=wt, col = factor(am), fill = factor(am)))+
stat_summary(fun.y = mean, geom = "bar", position = posn.d)+
stat_summary(fun.data = mean_se, fun.args = list(mult = 1), geom = "errorbar", width = 0.1, position =posn.d)
但我想說的是有些不同。 對於具有相同級別的組類別,有多於兩個變量。
(例如, 組: 「選項A」, 「選項B」, 「選項C」
水平爲每個組:0,1)
實施例的數據:
mtcars$OptionA=sample(0:1, 32, replace = T)
mtcars$OptionB=sample(0:1, 32, replace = T)
mtcars$OptionC=sample(0:1, 32, replace = T)
mtcars
我可以這樣有R的陰謀? 任何幫助將是偉大的。謝謝:)
非常感謝。它幫助了很多! :) – Amy
@Amy,不客氣。我想你可以很容易地在上面的代碼中添加'stat_summary'。 – Edu