Skip to content

Guides with duplicate labels do not get merged properly #3573

Closed
@MartinEarle

Description

@MartinEarle

I have come across a small issue with manually selecting colour and linetype for my data. I want to manually select values for these aesthetics and relabel them. In this instance, I am showing the "treatment" from a factorial experiment with the label, and an additional factor with the colour. The linetype distinguishes the experiment from the control. Below is my code:

ggplot(df,aes(date,mean))+ 
  geom_line(size=0.5,aes(linetype=sample_name,colour=sample_name))+
  theme_classic()+
  theme(legend.margin=margin(0,0,0,0),legend.box.margin=margin(0,-10,-8,-10),legend.text=element_text(size=11),legend.position="top")+
  scale_x_date(expand=c(0,0),labels=date_format("%m/%d"),breaks = seq.Date(as.Date(date_min),as.Date(date_max),
                                                                              by = "month"),limits = as.Date(c("2018-1-1","2018-9-26")))+
  scale_y_continuous(limits=c(6,9),expand = c(0,0),breaks = seq(6,9.,0.5))+
  scale_colour_manual(labels = c("A", "B", "C", "D", "E", "F"),breaks=c("Inflow","Filter 3","Filter 7","Filter 8", "Filter 9", "Filter 10"),values = c('Black','#004f71','#4c839b','#99b8c6','#C0504D','#d28482'))+
  scale_linetype_manual(labels = c("A", "B", "C", "D", "E", "F"),breaks=c("Inflow","Filter 3","Filter 7","Filter 8", "Filter 9", "Filter 10"),values=c("dashed","solid","solid","solid","solid","solid"))+
  labs(color="", linetype="")+
  xlab("Date")+ylab("Data")

This results in the following plot:

Ex1

As you can see, the labels for C & D are both duplicated. This does not occur if I rename the second "C" and "D" to "E" and "F", as shown below, or if I hide one of the guides (not shown).

Ex2

I can provide some data to recreate this, if desired.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorguides 📏

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions