如何重新排列 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())
如何重新排列 x 轴,使其按以下顺序排列:“抑郁”、“焦虑”、“健康”。
侧面是“中性”、“损失”、“获胜”
谢谢!
最佳答案
这两者都可以通过传入级别
来完成:
vids$mental <- factor(vids$publish_when, levels=c("Depressed", "Anxious", "Healthy"))
vids$outcome <- factor(vids$outcome, levels=c("Neutral", "Loss", "Win"))
额外提示:如果您的绘图遵循/反射(reflect)必要的顺序很重要,请对您想要排序的任何变量执行相同的操作。
如果因子是有序因子(Hot
、Medium
、Cool
)或风险级别,请使用ordered
相反。然后,您的可视化将遵循此顺序。
ggplot
或 ggpubr
实际上不是问题。
关于r - 特定的 x 轴/面顺序 ggpubr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50068933/