Home > OS >  Adding legend to ggplot putting two scatter-plots onto one graph
Adding legend to ggplot putting two scatter-plots onto one graph

Time:10-09

I have been trying to add a legend and amend it, however after spending hours on different websites, books, etc. I was unable to do it.

Data used to produce below graphs -> enter image description here

Edit: To place the scatter plots as 2 graphs in 1 chart you can use facet_wrap() like below.

...
  facet_wrap(~set)  
  stat_regline_equation(aes(color = set),
                        show.legend = FALSE,
                        label.y = c(0.25, 0.25))  
  stat_cor(aes(color = set),
           label.y = c(0.23, 0.23),
           show.legend = FALSE)  
...

enter image description here

If you want both to have their own y axis, add scales = "free_y" to facet_wrap().

enter image description here

  • Related