aes映射ggplot2一致性

时间:2016-09-22 00:58:00

标签: r ggplot2

我正在学习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映射。

任何帮助表示赞赏

0 个答案:

没有答案