-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent behavior of geom_line and geom_smooth wrt. color #498
Comments
I'm still not sure what's causing the bug, but if you just want black lines, do |
Is this a bug? I think it might be expected behavior. In this case, the color in foo <- data.frame(x = rnorm(30), y = rnorm(30), z = 1:3)
foo$z <- factor(foo$z)
# Setting color in scale has no effect
ggplot(foo, aes(x = x, y = y, linetype=z)) + geom_smooth() +
scale_colour_manual(values = c("red"))
ggplot(foo, aes(x = x, y = y, linetype=z)) + geom_line() +
scale_colour_manual(values = c("red"))
# Setting it directly works
ggplot(foo, aes(x = x, y = y, linetype=z)) + geom_smooth(colour="red")
ggplot(foo, aes(x = x, y = y, linetype=z)) + geom_line(colour="red") As for the issue, regarding why the other lines don't show up when # Only one line shows up, in black
ggplot(foo, aes(x = x, y = y, linetype=z, colour = z)) + geom_smooth() +
scale_colour_manual(values = c("black"))
# First and third lines show up
ggplot(foo, aes(x = x, y = y, linetype=z, color = z)) + geom_smooth() +
scale_color_manual(values = c("black",NA,"red"))
I think it would probably be a good idea to print a message when not enough values are specified in a discrete scale. Update: I checked 0.8.9, and the behavior is the same. |
Agreed, this is expected behaviour. I'm not sure if a warning would be the right thing to do: How would that differ from the following bevahiour? ggplot(foo, aes(x = x, y = y, linetype=z, color = z)) +
geom_smooth() +
scale_colour_manual(values = "black", na.value = "red") But maybe that behaviour is undesirable? |
I have a hard time envisioning situations where using I guess the NA substitution makes sense for continuous color scales, but in those cases, the NAs are calculated from the scale -- they're not manually specified, as is the case here. |
Good point. I'll make the fix. |
Hrm. I have lost track somewhat of the discussion. I think I understand why the From the point of view of a user, it would be convenient if a quick print-suitable version of a graph could be generated by
That turns this from a bug report into a feature request, I suppose. I've looked at the code involved, and while I wouldn't say that I have wrapped my head around all its object-orientedness, I could take a crack at implementing these things if there is interest in them. |
The manual scales issue is now #512. Currently, there's no way to change the default aesthetics of geoms on mass. This may be something that will be possible after the layer rewrite. Could you please file that as a separate issue, outlining your use case? Thanks! |
geom_smooth
does not pick up its color from ascale_color_manual
unlesscolor
is explicitly added to the aesthetic;geom_line
does. Perhaps this is best explained by illustration:It seems like a bug for the two functions to behave differently, but I can't tell which one is misbehaving. I would prefer if they both behaved like
geom_line
, because I am trying to "zero out" all the colors in a graph with thescale_color_manual
(for a dead-tree version of a graph). If there is an alternative, better way to do that, I would also be interested in hearing about it...Thanks.
The text was updated successfully, but these errors were encountered: