我似乎無法讓這些誤差條以條形為中心。我認為position_dodge2(width=0.5)可以解決問題,但改變width論點似乎沒有任何作用?
例子:
set.seed(1234)
library(tidyverse)
data.frame(rep=c(rep(1,15),rep(2,15)),
num=rep(c(sample(c(1:15),15)),2),
sex=rep(c(sample(c("m","f"),15,T))),
conc=rep(c(rep("1:1000",5),rep("1:100",5),rep("1:10",5)),2),
c1=c(sample(c(0:100),15,T),sample(c(0:100),15,T)),
c2=c(sample(c(0:100),15,T),sample(c(0:100),15,T)),
c3=c(sample(c(0:100),15,T),sample(c(0:100),15,T)),
c4=c(sample(c(0:100),15,T),sample(c(0:100),15,T)))%>%
pivot_longer(cols=c(c1,c2,c3,c4),
names_to="compound",
values_to="time")%>%
ggplot(aes(x=compound,
y=time,
group=rep,
fill=as.factor(rep)))
stat_summary(fun="mean",geom="col",
position=position_dodge2(width=1))->p1
p1 facet_grid(conc~.)
p1 stat_summary(fun.data="mean_se",geom="errorbar",
width=0.5,
position=position_dodge2(width=0.5))
facet_grid(conc~.)
p1 stat_summary(fun.data="mean_se",geom="errorbar",
width=0.5,
position=position_dodge2(width=1))
facet_grid(conc~.)
p1 stat_summary(fun.data="mean_se",geom="errorbar",
width=0.5,
position=position_dodge2(width=0.1))
facet_grid(conc~.)
p1 stat_summary(fun.data="mean_se",geom="errorbar",
width=0.5,
position=position_dodge(width=0.5))
facet_grid(conc~.)
uj5u.com熱心網友回復:
我相信這是position_dodge2()躲避錯誤欄的錯誤,因為我遇到了同樣的問題。閃避點幾何圖形position_dodge2()也同樣困難。
解決方法是使用position_dodge(),盡管您可能需要稍微調整一下 dodge 和 geom 本身的寬度才能使事情看起來正確:
p1 stat_summary(fun.data="mean_se",geom="errorbar",
width=0.5,
position=position_dodge(width=0.9))
facet_grid(conc~.)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/420812.html
標籤:
