如何更改下图中 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
剧情:
最佳答案
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
关于r - ggpubr:更改 stat_compare_means Kruskal-Wallis p 值的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48550525/