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
I'm pretty sure this is a regression as I used to make plots like this all the time (e.g., plotting traces of ensemble forecasts). It seems that specifying the group aesthetic overrides, rather than being combined with, other aesthetics such as color.
Reprex:
library(ggplot2)
library(dplyr)
# function to generate tracesfake_data=function() {
bind_rows(
tibble(x=1:10, y= sort(rnorm(10))),
tibble(x=1:10, y= sort(rnorm(10))),
tibble(x=1:10, y= sort(rnorm(10))),
.id="trace"
)
}
# works as expectedtraces= fake_data()
ggplot(traces) + aes(x=x, y=y, color="v1", group=trace) + geom_line()
Hi there, thanks for the report. This behaviour has at least existed since ggplot2 3.0.0, so this has been around for 5 years now. A colour is allowed to vary within a group, so inferring grouping from colours would break quite some code out there. I'm inclined to think that this is not a bug.
The "workaround" you list is the correct way of dealing with this situation. If you manually set the group aesthetic you have to set it exactly how you want it. You can't expect ggplot to take your group assignment and somehow modify it based on other aesthetics you have set. That makes no sense.
You can't expect ggplot to take your group assignment and somehow modify it based on other aesthetics you have set
I mean, that's how it works with aesthetics in general---my misunderstanding was in thinking group was an additional aesthetic rather than the explicit way to define the group structure implicitly set by color/linetype/etc. The documentation makes this clear so I must be misremembering how I used the group aesthetic in the past. Sorry about that!
I'm pretty sure this is a regression as I used to make plots like this all the time (e.g., plotting traces of ensemble forecasts). It seems that specifying the
group
aesthetic overrides, rather than being combined with, other aesthetics such ascolor
.Reprex:
Session Info:
The text was updated successfully, but these errors were encountered: