特定的x轴/刻面顺序ggpubr

时间:2018-04-27 19:14:08

标签: r ggpubr

如何在ggpubr上重新排列x轴和刻面的顺序?

例如,我对以下图表有以下代码

ggbarplot(Cue, x = "Primary_Dx", y = "Target.RT", fill ="Primary_Dx", palette = "jco", add = "mean_se", facet.by = "Cue", 
          legend.title = "Diagnosis", title = "Average Response Time per Cue",
          xlab = "Diagnosis", ylab = "Average Response Time") + 
  stat_compare_means(comparisons = my_comparisons, label = "p.signif", label.y = c(305, 325, 350)) +
  theme_linedraw() + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

enter image description here

如何重新排列x轴,使其按以下顺序排列:"郁闷","焦虑","健康"。

这方面是"中立","损失","赢"

谢谢!

1 个答案:

答案 0 :(得分:2)

这两项都可以通过传递levels

来完成
vids$mental <- factor(vids$publish_when, levels=c("Depressed", "Anxious", "Healthy"))
vids$outcome <- factor(vids$outcome, levels=c("Neutral", "Loss", "Win"))

额外提示:对于您要订购的任何变量,如果重要的是您的绘图将遵循/反映必要的顺序。

如果因素是有序因子(HotMediumCool)或风险等级,请改用ordered。然后,您的可视化中将遵循此订单。

ggplotggpubr实际上不是问题。