我正在学习ggplot2并有以下示例示例:
library(ggplot2)
# Aesthetic gets mapped correctly here
# don't mention `aes` in `geom_point`
ans2 <- ggplot(anscombe, aes(x = x2, y = y2))
ans2 <- ans2 + geom_point(colour = "blue", size = 5)
ans2
# Aesthetic does NOT get mapped correctly here
# explicitly mention `aes` in `geom_point`!
# this should work best, I would've thought
ans3 <- ggplot(anscombe, aes(x = x2, y = y2))
ans3 <- ans3 + geom_point(aes(colour = "blue", size = 5))
ans3
ans2
的情节与正确的色彩美学一致。但是ans3
无效。 "blue"
颜色选项未在geom_point()中注册。为什么审美映射在ans2
但不在ans3
另外,请采用以下简单的规范示例:
# Aesthetic gets mapped correctly here
# explicitly mention `aes` in `geom_point`
b2 <- ggplot(mpg, aes(x = cty, y = hwy))
b2 + geom_point(aes(col = fl, size = displ))
# Aesthetic does NOT get mapped correctly here
# don't mention `aes` in `geom_point`
b3 <- ggplot(mpg, aes(x = cty, y = hwy))
b3 + geom_point(col = fl, size = displ)
为什么b2
有效并且b3
抛出object 'fl' not found
错误?
我认为b3
与上面的ans2
类似,后者适用于aes
映射。
任何帮助表示赞赏