【问题标题】:Change position of stat_compare_means() in the plot using ggplot使用 ggplot 在图中更改 stat_compare_means() 的位置
【发布时间】:2023-03-23 10:32:01
【问题描述】:

我有这个带有 ggpubr::stat_compare_means() 函数的 ggplot 图:

如您所见,Wilcoxon 检验与左侧条形上的一些点重叠。

如何将文本向右移动?

【问题讨论】:

标签: r ggplot2


【解决方案1】:

按照@Mikolajm 的建议,您可以在stat_compare_means() 函数中使用label.xlabel.y 参数来定位您的文本。 label.x 参数更改文本在 x 轴上的位置,label.y 参数更改文本在 y 轴上的位置。

例如(这在逻辑上没有意义),我使用了mtcars 数据集。

require(ggplot2)
require(ggpubr)


ggboxplot(mtcars, x = "am", y = "carb",
          color = "am") +
  stat_compare_means(method = "wilcox.test",
                     label.x = 1.2, 
                     label.y = 10)

但是,如果我们将 label.x = 1.2label.y = 10 更改为 label.x = 0.6label.y = 6,图表将如下所示:

ggboxplot(mtcars, x = "am", y = "carb",
          color = "am") +
  stat_compare_means(method = "wilcox.test",
                     label.x = 0.6, label.y = 6)

【讨论】:

  • 谢谢。最后一个问题......有没有办法让情节中的文本居中?
  • “Wilcoxon, p = 0.74”还是传说?
  • “Wilcoxon,p = 0.74”,@DJV
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-17
  • 1970-01-01
  • 1970-01-01
  • 2022-11-27
  • 1970-01-01
相关资源
最近更新 更多