Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Duplicated legends in scatter plot

I’m plotting this ggplot2, but I can’t get rid of the duplicated legends. I assume this is a very silly mistake of mine, any ideas?

Plot:

legends

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Code:

data %>% 
  ggplot(., aes(x = X, y = Y)) +
  stat_summary(aes(group = LANGUAGE), position = position_dodge(width = 0)) +
  stat_summary(fun = mean, shape = 4) +
  stat_summary(aes(group = LANGUAGE, linetype = LANGUAGE, color = LANGUAGE),
               geom = "line", size = 1, position = position_dodge(width = 0)) +
  scale_color_manual(values = c(L1 = "yellow", L2 =  "green"),
                     name = "Language:") +
  theme_bw() +
  theme(legend.position = "right",
        legend.background = element_rect(color = "black"),  #bloco com legendas
        axis.text.x = element_text(angle = 0, hjust = 0.5, face = "bold"), # legenda de baixo
        plot.title = element_text(hjust = 0.5, face = "bold"),
        axis.text.y = element_text(face = "bold"))

Obs: the legend variable is a categorical variable named "LANGUAGE" (in caps) with two levels (L1 and L2)

Thanks in advance!

EDIT: I’ve just noticed that my error bars look weird, I keep getting:

No summary function supplied, defaulting to `mean_se()`

any ideas?

>Solution :

I think you need to make the titles (names) of the legends match. Try adding

scale_linetype(name = "Language:")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading