All, I am beginner to ggplot, and struggling with it. So, I bought Wickham's book. I don't understand the difference between these three code snippets:
ggplot(mpg, aes(cty, hwy)) +
geom_point(aes(colour = "green"))
vs.
ggplot(mpg, aes(cty, hwy)) +
geom_point(aes(colour = 1))
vs.
ggplot(mpg, aes(cty, hwy)) +
geom_point(aes(colour = "1"))
While I see the output, and the legend says "green" in one case and 1 in the other, but if we are really mapping an aesthetic to a variable, we should see the default pink color for all three, but this doesn't happen for the second item. Why is this? I'd appreciate any thoughts.
The second example provides a numerical value of 1 for the "colour" aesthetic ("color" would work just as well, by the way). Because a numerical value is provided, ggplot
assumes that a numerical color scale should be used. The default numerical color scale is a gradient that runs from bright blue to black. The default categorical scale, which is triggered by the first and third examples, is a rainbow scale with hue spacing equal to the number of levels in the provided variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.