ggpubr:更改stat_compare_means Kruskal-Wallis p值的字体大小 [英] ggpubr: change font size of stat_compare_means Kruskal-Wallis p-values

查看:200
本文介绍了ggpubr:更改stat_compare_means Kruskal-Wallis p值的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I change the font size of stat_compare_means on the plot below? I.e, change the "Kruskal-Wallis, p = 1.5e-09" and the other p-values font size? I would like to use a smaller font size than the default one...

下面的数据示例...

Following the data example...

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

情节:

推荐答案

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

该解决方案有点丰富,但是可以解决.我找不到另一种方法来覆盖 geom_signif 层的 textsize 参数,该参数是在首次调用 stat_compare_means 后创建的.

The solution is a bit copious but works. I couldn't find another way to overwrite the textsize parameter of the geom_signif layer that is created after the first call to stat_compare_means.

参数存储在此处: p $ layers [[2]] $ aes_params $ textsize ,可以手动修改.

The parameter is stored here: p$layers[[2]]$aes_params$textsize and can manually be modified.

如果您需要其他层的顺序可能与此示例不同的绘图的此操作,则可以使用which_layer 函数.rstudio.com/web/packages/gginnards/"rel =" noreferrer> gginnards 包可使用以下代码来检测此层(或任何其他层).

If you need this manipulation for another plot in which the order of the layers might differ from this example, you can use the which_layer function from the gginnards package to detect this layer (or any other) using the following code.

感谢 @KGee 指出 which_layer 函数已从<从0.3.0版开始的href ="https://cran.rstudio.com/web/packages/ggpmisc/" rel ="noreferrer"> ggpmisc 包.

Thanks to @KGee for pointing out that the which_layer function was moved from the ggpmisc package as of version 0.3.0.

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

像上面显示的那样更改 textsize 参数.

Change the textsize argument like shown above.

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

这篇关于ggpubr:更改stat_compare_means Kruskal-Wallis p值的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆