【发布时间】:2017-08-15 19:51:46
【问题描述】:
首先我运行这段代码,它运行良好(所有数据点都变成蓝色):
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy), color = "blue")
但是当我尝试像下面那样移动映射时,数据点变成黑色而不是蓝色。
这是为什么呢?
ggplot(data = mpg, mapping = aes(x = displ, y = hwy), color = "blue") + geom_point()
【问题讨论】:
-
试试
ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point(color = "blue") -
@G5W 的评论完全正确。只是为了让您对此有更多了解;想象一下,您还想用线 (
geom_line) 连接点,并且希望线是red。这就是你实现它的方式:ggplot(data = mpg, aes(x = displ, y = hwy)) + geom_point(color = "blue") + geom_line(color="red")。您可以对所有geoms 使用相同的映射 (aes)。
标签: r ggplot2 aesthetics