我希望AVANT图形排在第一位
dt = data.frame(AVG=c("POT","TPOT"),AVANT=c(5000,4400),APRES=c(5020,6500))
data = gather(dt, key="measure",value="value",c("AVANT","APRES"))
ggplot(data,aes(x=AVG, y=value,fill=AVG))+geom_bar(stat='identity')+facet_wrap(~measure)
答案 0 :(得分:0)
您只需要将度量值放在AVANT作为将APANT左侧的AVANT作为第一个级别的水平中即可。
data.ordered = mutate(data, measure=factor(measure, levels=c("AVANT","APRES")))
ggplot(data.ordered,aes(x=AVG, y=value,fill=AVG))+geom_bar(stat='identity')+facet_wrap(~measure)
答案 1 :(得分:0)
您可以在forcats::fct_rev
内部使用forcats::fct_relevel
或更安全地使用fcet_wrap
,例如
ggplot(data,aes(x=AVG, y=value,fill=AVG)) + geom_bar(stat='identity') +
facet_wrap(~fct_relevel(measure, c("APRES", "AVANT")))
#facet_wrap(~forcats::fct_rev(measure))