r语言 - 如何调整整体地块宽度(x轴大小)?



我一直在使用以下R脚本,但是x轴的宽度太宽. 有没有人能帮我调整一下x轴宽度?由于

library(ggpubr)
library(rstatix)
df <- ToothGrowth
df$dose <- as.factor(df$dose)
head(df, 6)
# Statistical test
stat.test <- df %>%
t_test(len ~ supp) %>%
add_significance()
stat.test

bxp <- ggboxplot(df, x = "supp", y = "len", fill = "supp", 
palette = c("#00AFBB", "#E7B800"),width = 0.5)

stat.test <- stat.test %>% add_xy_position(x = "supp")
bxp + stat_pvalue_manual(
stat.test, label = "T-test, p = {p}",
vjust = -1, bracket.nudge.y = 1
) +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.15)))+
scale_x_discrete(expand = c(2, 2))

听起来你可能想要调整主题的长宽比:

bxp + stat_pvalue_manual(
stat.test, label = "T-test, p = {p}",
vjust = -1, bracket.nudge.y = 1
) +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.15)))+
scale_x_discrete(expand = c(2, 2)) +
theme(
aspect.ratio = 2
)

最新更新