r - 特定的 x 轴/面顺序 ggpubr

标签 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 轴,使其按以下顺序排列:“抑郁”、“焦虑”、“健康”。

侧面是“中性”、“损失”、“获胜”

谢谢!

最佳答案

这两者都可以通过传入级别来完成:

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

额外提示:如果您的绘图遵循/反射(reflect)必要的顺序很重要,请对您想要排序的任何变量执行相同的操作。

如果因子是有序因子(HotMediumCool)或风险级别,请使用ordered 相反。然后,您的可视化将遵循此顺序。

ggplotggpubr 实际上不是问题。

关于r - 特定的 x 轴/面顺序 ggpubr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50068933/

相关文章:

r - 具有多个组的 stat_compare_means

r - ggplot/ggpubr : annotate_figure ignored when exporting plot

r - 使用 ggarrange 定位 ggplot 标签的问题

html - 如何将 reveal.js 中整个文本(标题、标题和正文)的位置更改为左上角?

r - 使用 R 中的 VECM 使用已知 X 即时预测 Y

r - ggpubr:更改 stat_compare_means Kruskal-Wallis p 值的字体大小

r - 将自定义注释添加到 p 值标签到 ggpubr stat_compare_means()

r - 具有变量 n 的滞后函数

R右矩阵除法

R:(中缀)运算符的两个定义之间的冲突:如何指定包?