Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify legend text of ggscatter() and label font of stat_cor() #111

Closed
zhan6073 opened this issue Sep 11, 2018 · 3 comments
Closed

modify legend text of ggscatter() and label font of stat_cor() #111

zhan6073 opened this issue Sep 11, 2018 · 3 comments

Comments

@zhan6073
Copy link

zhan6073 commented Sep 11, 2018

When I use the following code,
ggscatter(herita, x = 'sigma2', y = 'pre.mean', color = 'Group', add = "reg.line", conf.int = FALSE)+
stat_cor(aes(color = Group, label = paste(..rr.label.., ..p.label.., sep = ","))) +
scale_color_discrete(name = 'Group',labels = c(expression(italic(h)^2),expression(italic(H)^2)))
I got the plot
rplot
How do I removed the original legend and keep the revised? Also, I want to revise italic label to 'R2' and 'P' and modify their font size. I tried code,stat_cor(aes(color = Group,label = paste0(expression(R^2)," = ", ..r.., ", P = ", ..p..))) and font(), but failed. It seems no parameters for these.

@xavierjob
Copy link

Did you/anyone figure this out? I have the same issue.

@zhan6073
Copy link
Author

zhan6073 commented Jul 15, 2019

Use geom_point() instead of ggscatter() to address two legends issue.
For revising the labels, use
stat_cor(aes(color = Group,
label = paste(paste("R^2~=", ..rr..),
paste("P
=", ..p..),sep = ',~')),
size = 3, # geom_text size
show.legend = F # remove 'a' in the legend.key
)

@kassambara
Copy link
Owner

Fixed now, thanks!

library(ggpubr)
#> Le chargement a nécessité le package : ggplot2

# Reg line without confidence band
ggscatter(
  iris, x = 'Sepal.Length', y = 'Petal.Length', color = 'Species', 
  add = "reg.line", conf.int = FALSE
  )+
  stat_cor(aes(color = Species, label = paste(..rr.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE) +
  scale_color_discrete(
    name = 'Species', 
    labels = c(expression(italic(h)^2), expression(italic(H)^2), expression(italic(HH)^2)) 
    ) 
#> `geom_smooth()` using formula 'y ~ x'

# Reg line with confidence band
ggscatter(
  iris, x = 'Sepal.Length', y = 'Petal.Length', color = 'Species', 
  add = "reg.line", conf.int = TRUE
)+
  stat_cor(aes(color = Species, label = paste(..rr.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE) +
  # setting legend for color (point, line)
  scale_color_discrete(
    name = 'Species', 
    labels = c(expression(italic(h)^2), expression(italic(H)^2), expression(italic(HH)^2)) 
  ) +
  # setting legend for fill (confidence band)
  scale_fill_discrete(
    name = 'Species', 
    labels = c(expression(italic(h)^2), expression(italic(H)^2), expression(italic(HH)^2)) 
  ) 
#> `geom_smooth()` using formula 'y ~ x'

Created on 2020-05-08 by the reprex package (v0.3.0.9001)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants