【问题标题】:ggpubr: change font size of stat_compare_means Kruskal-Wallis p-valuesggpubr:更改 stat_compare_means Kruskal-Wallis p 值的字体大小
【发布时间】:2018-07-11 01:21:25
【问题描述】:

如何更改下图中stat_compare_means 的字体大小?即,更改“Kruskal-Wallis,p = 1.5e-09”和其他 p 值字体大小?我想使用比默认字体更小的字体...

以下数据示例...

library(ggpubr)
data("ToothGrowth")
compare_means(len ~ dose,  data = ToothGrowth)

# Visualize: Specify the comparisons I want
my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") )

# Plotting
ggboxplot(ToothGrowth, x = "dose", y = "len",
          color = "dose", palette = "jco")+ 
stat_compare_means(comparisons = my_comparisons)+ # Add pairwise comparisons p-value
stat_compare_means(label.y = 50)     # Add global p-value

剧情:

【问题讨论】:

    标签: r ggplot2 kruskal-wallis ggpubr


    【解决方案1】:
    your_font_size <- 2
    
    p <- ggboxplot(ToothGrowth, x = "dose", y = "len", color = "dose", palette = "jco") + 
     stat_compare_means(comparisons = my_comparisons) + 
     stat_compare_means(label.y = 50, size = your_font_size)
    
    p$layers[[2]]$aes_params$textsize <- your_font_size
    p
    

    解决方案有点丰富,但很有效。我找不到另一种方法来覆盖在第一次调用stat_compare_means 后创建的geom_signif 层的textsize 参数。

    参数存放在这里:p$layers[[2]]$aes_params$textsize,可以手动修改。

    如果您需要对图层顺序可能与此示例不同的另一个绘图进行此操作,您可以使用 gginnards 包中的 which_layer 函数来检测此图层(或任何其他图层),使用以下命令代码。

    感谢 @KGee 指出 which_layer 函数已从 ggpmisc 包中移出 0.3.0 版。

    library(gginnards)
    which_layers(p, "GeomSignif")
    ## [1] 2
    

    如上所示更改textsize 参数。

    p$layers[[which_layers(p, "GeomSignif")]]$aes_params$textsize <- your_font_size
    

    【讨论】:

      猜你喜欢
      • 2020-04-17
      • 2015-04-11
      • 2019-06-14
      • 2015-11-23
      • 2022-01-12
      • 2020-09-09
      • 2021-09-06
      • 2019-01-09
      • 2015-05-03
      相关资源
      最近更新 更多