0

I want to increase the font size of autogenerated r2 and p value. I used the code like + theme(text = element_text(size = 18)) but it did not make any changes?

The code used are given below

# 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))

2 Answers 2

3

stat_cor uses geom_text. The documentation in help("geom_text") tells you that it "understands" the size aesthetic.

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)
Sign up to request clarification or add additional context in comments.

1 Comment

You know this, adding + guides(color = guide_legend(override.aes = list(size = 0))) will remove the a in front of the lines in the legend.
0

stat_cor takes other arguments which pass pass to geom_text or geom_label, including "size" and "colour", so you can change your command like below

You can also try:

stat_cor( aes(label = paste(..rr.label.., ..p.label.., sep = "~`,`~")),
label.x = 0.5, method = "spearman",label.sep = "\n", size = 10)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.