如何增加gg散点图中自动生成的R和p值的字体大小?

问题描述 投票:0回答:1

我想增加自动生成的r2和p值的字体大小。我用过这样的代码

+ theme(text = element_text(size = 18))
但没有做出任何改变?

使用的代码如下

# Load data
data("mtcars")
df <- mtcars
# Convert cyl as a grouping variable
df$cyl <- as.factor(df$cyl)


ggscatter(df, x = "wt", y = "mpg",
          add = "reg.line",                         
          conf.int = TRUE,                          
          color = "cyl", palette = "jco",           
          shape = "cyl"                     
          )+
  stat_cor(aes(color = cyl), label.x = 3) +
 theme(text = element_text(size = 18))
r ggplot2 scatter-plot font-size pearson-correlation
1个回答
0
投票
library(ggpubr)

#recommended way
ggscatter(df, x = "wt", y = "mpg",
          add = "reg.line",                         
          conf.int = TRUE,                          
          color = "cyl", palette = "jco",           
          shape = "cyl",
          cor.coef = TRUE,
          cor.coeff.args = list(aes(color = cyl), label.x = 3),
          cor.coef.size = 12
)

#alternatively
ggscatter(df, x = "wt", y = "mpg",
          add = "reg.line",                         
          conf.int = TRUE,                          
          color = "cyl", palette = "jco",           
          shape = "cyl"                     
) +
  stat_cor(aes(color = cyl), label.x = 3, size = 12)
© www.soinside.com 2019 - 2024. All rights reserved.