該函式stat_pvalue_manual()將使用 將 p 值添加到箱線圖中ggboxplot。但是,列印的 p 值有時會有很多位數。我想將小數位數限制為 3。我該怎么做?
從下圖中您會看到 versicolor 和 virginica 的 p 值為 5 個小數位,我如何調整下面的代碼以報告 3 個小數位(即 0.009)?
library(ggplot2)
library(tidyverse)
library(dplyr)
library(rstatix)
library(ggpubr)
test <- iris
test$Species <- as.factor(test$Species)
test.aov <- test %>% anova_test(Sepal.Width ~ Species)
test.tukey <- test %>% tukey_hsd(Sepal.Width ~ Species)
test.tukey <- test.tukey %>% add_xy_position(x = "Species")
ggboxplot(test, x = "Species", y = "Sepal.Width", outlier.shape = NA)
stat_pvalue_manual(test.tukey, hide.ns = TRUE, y.position = c(5,4.5,4), label = "p = {p.adj}")
geom_jitter(shape=16, alpha = 0.4, size = 2, position=position_jitter(0.1))
labs(subtitle = get_test_label(test.aov, detailed = T))
scale_y_continuous(breaks = seq(0,5,1), limits = c(0,5))
xlab("Species")
ylab("Sepal Length")
theme_bw()
theme(panel.grid = element_blank(),
plot.subtitle = element_text(vjust = -105, hjust = 0.05),
text = element_text(size = 14),
axis.text.x = element_text(size = 16, color = "black"),
axis.text.y = element_text(size = 16, color = "black"))
uj5u.com熱心網友回復:
你可以使用label = "p = {scales::pvalue(p.adj)}"
ggboxplot(test, x = "Species", y = "Sepal.Width", outlier.shape = NA)
stat_pvalue_manual(test.tukey, hide.ns = TRUE, y.position = c(5,4.5,4),
label = "p = {scales::pvalue(p.adj)}")
geom_jitter(shape=16, alpha = 0.4, size = 2, position=position_jitter(0.1))
labs(subtitle = get_test_label(test.aov, detailed = T))
scale_y_continuous(breaks = seq(0,5,1), limits = c(0,5))
xlab("Species")
ylab("Sepal Length")
theme_bw()
theme(panel.grid = element_blank(),
plot.subtitle = element_text(vjust = -105, hjust = 0.05),
text = element_text(size = 14),
axis.text.x = element_text(size = 16, color = "black"),
axis.text.y = element_text(size = 16, color = "black"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/443250.html
