1

Please find a reprex below but this is what I currently have:

enter image description here

I don't need to have a separate legend for each of the plots but I would like the legend to be divided by the facets. It can just be by having a separate title:

Cash flow indicator ratios

  • Ratio xx

  • Ratio yy

  • Ratio zz

Growth ratios

  • Ratio aa

  • Ratio bb

  • Ratio cc

...

Does anyone have any suggestion on how to do that?

Thank you!!

REPREX:

mtcars$names <- rownames(mtcars)
mtcars <- mtcars %>%
   mutate(group = case_when(gear == 3 ~ "A", 
                            gear == 4 ~ "B", 
                            gear == 5 ~ "C"))

ggplot(data = mtcars, aes(mpg, disp, color = names, group =group)) +
  geom_line(size = 1) +
  geom_point()+
  guides(color=guide_legend(ncol=1))+
  facet_wrap(~ group)

I would like to have the legend divided in Groups A, B, C.

InesGuardans
  • 129
  • 10
  • 1
    without a reproducible example it is almost impossible to help you. If your real data is to large or complex, try using a public dataset (such as `mtcars`) to illustrate your issue. – Limey Jun 19 '20 at 10:30
  • Just added one. – InesGuardans Jun 19 '20 at 10:57
  • Something is wrong. It is `mtcars` and you need to specify `mpg` and `disp` in `aes` – cmirian Jun 19 '20 at 11:06
  • Please check now! – InesGuardans Jun 19 '20 at 11:35
  • 1
    Check out this thread, which is basically a dupe. However, not with accepted answer, so won't mark it as a dupe https://stackoverflow.com/questions/56064662/how-can-i-organize-my-legend-into-subgroups – tjebo Jun 19 '20 at 11:47
  • 1
    Or this thread - you can create a fake legend https://stackoverflow.com/questions/49064845/add-annotation-and-segments-to-groups-of-legend-elements/49077005#49077005 – tjebo Jun 19 '20 at 11:53

0 Answers0