如何在下图中更改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绘图:

发布于 2018-02-01 04:37:09
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指出,从0.3.0版开始,which_layer函数已从ggpmisc包中移出。
library(gginnards)
which_layers(p, "GeomSignif")
## [1] 2如下所示更改textsize参数。
p$layers[[which_layers(p, "GeomSignif")]]$aes_params$textsize <- your_font_sizehttps://stackoverflow.com/questions/48550525
复制相似问题