Description
I think I found a problem with the functions scale_color_discrete()
and scale_colour_discrete()
. I thought that one of these functions was just an alias for the other, so in theory they should behave exactly the same.
In one of my recent projects, I needed a global color scale, so I thought that I'd redefine one of these functions with custom colors (let me know if this is not a good idea and if there is a better approach). It turns out that this only works for scale_colour_discrete()
, but not for scale_color_discrete()
!
Redefining the scale_color_discrete()
function does not have the desired effect (easy should be green, medium should be blue, and hard should be red):
library(ggplot2)
scale_color_discrete = function(...) {
scale_color_manual(..., values=c(easy="green", medium="blue", hard="red"))
}
df = data.frame(
x=1:3,
y=1:3,
z=c("easy", "medium", "hard")
)
ggplot(data=df, mapping=aes(x=x, y=y, color=z)) +
geom_point(size=10)
This only works with the scale_colour_discrete()
function (same code as before, the only difference is the spelling of the function):
library(ggplot2)
scale_colour_discrete = function(...) {
scale_color_manual(..., values=c(easy="green", medium="blue", hard="red"))
}
df = data.frame(
x=1:3,
y=1:3,
z=c("easy", "medium", "hard")
)
ggplot(data=df, mapping=aes(x=x, y=y, color=z)) +
geom_point(size=10)
I know that @hadley will probably argue that "colour" is the correct spelling, but I'd still say that this qualifies as a bug 😄.