使用 ggplot2 绘制具有多个因素和明确定义的标准偏差的漂亮箱线图
Graph with ggplot2 a nice boxplot with multiple factors and explicitly defined Standard deviations
我有一个数据框,它只包含每组的平均值,并有一个明确的数字定义每组(上限和下限)的标准差。这是数据框:
dat <- read.table(text = '
mean dist group lower upper rev.lower factor
-4.058047 0 P -4.096849 -4.019245 -4.096849 dd
-4.001524 0 Ps -4.040326 -3.962722 -4.040326 dd
-3.956972 0 P -4.028551 -3.885393 -4.028551 tt
-4.050114 0 Ps -4.121694 -3.978535 -4.121694 tt
-2.859591 0 P -2.955156 -2.764026 -2.955156 aa1
-3.017559 0 Ps -3.113124 -2.921994 -3.113124 aa1
-3.094085 0 P -3.196434 -2.991736 -3.196434 aa4
-3.265121 0 Ps -3.367470 -3.162772 -3.367470 aa4
-4.283909 0 P -4.352606 -4.215213 -4.352606 ba1
-4.344173 0 Ps -4.412870 -4.275477 -4.412870 ba1
-4.594736 0 P -4.664228 -4.525243 -4.664228 bh2
-4.545442 0 Ps -4.614935 -4.475950 -4.614935 bh2
-4.843653 0 P -4.925350 -4.761957 -4.925350 g6
-4.492781 0 Ps -4.574478 -4.411085 -4.574478 g6
-4.072374 0 P -4.205603 -3.939145 -4.205603 gx
-3.742987 0 Ps -3.876216 -3.609758 -3.876216 gx',head=T, fill=T)
我试过这个:
ggplot(dat, aes(factor(factor), value)) + geom_boxplot(aes(fill=factor(group)))
它有效,但我不确定如何绘制下限和上限 SD
每组的每个因素。请告知我如何绘制此图表...
非常感谢
尝试添加
your_barplot + geom_errorbar(aes(ymax=upper,
ymin=lower),
position=position_dodge(0.9),
data=dat)
我有一个数据框,它只包含每组的平均值,并有一个明确的数字定义每组(上限和下限)的标准差。这是数据框:
dat <- read.table(text = '
mean dist group lower upper rev.lower factor
-4.058047 0 P -4.096849 -4.019245 -4.096849 dd
-4.001524 0 Ps -4.040326 -3.962722 -4.040326 dd
-3.956972 0 P -4.028551 -3.885393 -4.028551 tt
-4.050114 0 Ps -4.121694 -3.978535 -4.121694 tt
-2.859591 0 P -2.955156 -2.764026 -2.955156 aa1
-3.017559 0 Ps -3.113124 -2.921994 -3.113124 aa1
-3.094085 0 P -3.196434 -2.991736 -3.196434 aa4
-3.265121 0 Ps -3.367470 -3.162772 -3.367470 aa4
-4.283909 0 P -4.352606 -4.215213 -4.352606 ba1
-4.344173 0 Ps -4.412870 -4.275477 -4.412870 ba1
-4.594736 0 P -4.664228 -4.525243 -4.664228 bh2
-4.545442 0 Ps -4.614935 -4.475950 -4.614935 bh2
-4.843653 0 P -4.925350 -4.761957 -4.925350 g6
-4.492781 0 Ps -4.574478 -4.411085 -4.574478 g6
-4.072374 0 P -4.205603 -3.939145 -4.205603 gx
-3.742987 0 Ps -3.876216 -3.609758 -3.876216 gx',head=T, fill=T)
我试过这个:
ggplot(dat, aes(factor(factor), value)) + geom_boxplot(aes(fill=factor(group)))
它有效,但我不确定如何绘制下限和上限 SD
每组的每个因素。请告知我如何绘制此图表...
非常感谢
尝试添加
your_barplot + geom_errorbar(aes(ymax=upper,
ymin=lower),
position=position_dodge(0.9),
data=dat)