Home > database >  Duplicated legends in scatter plot
Duplicated legends in scatter plot

Time:09-16

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

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?

CodePudding user response:

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

scale_linetype(name = "Language:")
  • Related