如何移除ggstatsplot图表右侧的‘pairwise test’文本?
解决ggstatsplot中无法移除右侧 pairwise test 注释文本的问题
pairwise.display = 'none'仅控制显著性连线条的显示,右侧的"pairwise test:Dunn, bars shown: not significant"文本是由 pairwise 检验的运行状态生成的,因此需要额外设置参数来移除它,以下是两种可行方案:
方案一:关闭 pairwise 检验流程
直接在ggbetweenstats中添加pairwise.comparisons = FALSE参数,彻底关闭 pairwise 检验的运行,这样就不会生成相关注释文本:
plot1 <- ggstatsplot::ggbetweenstats( data = boxplot.Age, x = cluster, y = Age, color = group, title = "Age Box Plot", subtitle = "Grouped by cluster", type = "nonparametric", comparisons_correction = "holm", results.subtitle = FALSE, pairwise.display = 'none', pairwise.comparisons = FALSE # 新增参数关闭成对检验 )
方案二:移除已生成的注释图层
如果需要保留 pairwise 检验的计算结果但隐藏注释文本,可以手动移除对应的图层。该注释通常是GeomRichtext类型的图层,可通过以下代码筛选保留其他图层:
# 生成原始图表 plot1 <- ggstatsplot::ggbetweenstats( data = boxplot.Age, x = cluster, y = Age, color = group, title = "Age Box Plot", subtitle = "Grouped by cluster", type="nonparametric", comparisons_correction = "holm",results.subtitle =FALSE, pairwise.display = 'none') # 移除注释图层 plot1$layers <- plot1$layers[sapply(plot1$layers, function(layer) { class(layer$geom)[1] != "GeomRichtext" })]
内容的提问来源于stack exchange,提问作者Emily-Jane
相关产品推荐
相关产品推荐

