You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Guides with duplicate labels do not get merged properly #3573
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:
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).
I can provide some data to recreate this, if desired.
I can't seem to reproduce this...perhaps you could pair down your example and render it using the reprex package? The reprex I was using to try to replicate your error is here:
Just simplifying this a tiny bit...the determining factor looks to be that there are two manual scales that are trying to be merged where any(breaks != labels).
Upon closer inspection, it looks like it's a general problem with duplicate labels and how guides are merged (using .$labels as an implicit key for merge() doesn't work when there are duplicates):
We could (1) change the way merging happens (cbind() should work, given that the breaks and labels are hashed to determine if the guides ever get merged), or (2) enforce unique labels.
As a workaround, one could recode the values before they get to ggplot2 (e.g., using fct_recode()).
changed the title [-]Multiple scale_xxx_manual do not properly label in legend with duplicate labels.[/-][+]Guides with duplicate labels do not get merged properly[/+]on Oct 17, 2019
Please don't enforce unique labels. There are valid cases for duplicated labels, e.g. making multiple labels equal to "" to zero them out. Wouldn't the correct approach merge on breaks rather than labels? Breaks have to be unique by definition (I think).
Activity
paleolimbot commentedon Oct 16, 2019
Welcome @MartinEarle!
I can't seem to reproduce this...perhaps you could pair down your example and render it using the reprex package? The reprex I was using to try to replicate your error is here:
MartinEarle commentedon Oct 17, 2019
Hi @paleolimbot!
Sorry, I did not understand how Reprex worked before, but I have now recreated my issue now with the mpg dataset and have copied it below:
Created on 2019-10-17 by the reprex package (v0.3.0)
I am using R 3.6.0.
paleolimbot commentedon Oct 17, 2019
Just simplifying this a tiny bit...the determining factor looks to be that there are two manual scales that are trying to be merged where
any(breaks != labels).Created on 2019-10-17 by the reprex package (v0.2.1)
paleolimbot commentedon Oct 17, 2019
Upon closer inspection, it looks like it's a general problem with duplicate labels and how guides are merged (using
.$labelsas an implicit key formerge()doesn't work when there are duplicates):ggplot2/R/guide-legend.r
Lines 232 to 233 in 115c396
Created on 2019-10-17 by the reprex package (v0.2.1)
We could (1) change the way merging happens (
cbind()should work, given that the breaks and labels are hashed to determine if the guides ever get merged), or (2) enforce unique labels.As a workaround, one could recode the values before they get to ggplot2 (e.g., using
fct_recode()).[-]Multiple scale_xxx_manual do not properly label in legend with duplicate labels.[/-][+]Guides with duplicate labels do not get merged properly[/+]clauswilke commentedon Oct 17, 2019
Please don't enforce unique labels. There are valid cases for duplicated labels, e.g. making multiple labels equal to
""to zero them out. Wouldn't the correct approach merge on breaks rather than labels? Breaks have to be unique by definition (I think).Fix guide merging when there are repeated labels (#3599, fixes #3573)
lock commentedon May 5, 2020
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/