首页 文章

将对象传递给ggplot中的aes()并将相同的对象传递到ggplot之外的区别

提问于
浏览
0

将物种映射到ggplot和geom_point内部的颜色美学有什么不同 . 我正在使用虹膜数据集 .

ggplot(aes(x = Sepal.Length, y = Petal.Length, color = Species), data = 
trainData)+
geom_point()+
geom_smooth()

AND

ggplot(aes(x = Sepal.Length, y = Petal.Length), data = trainData)+
geom_point(aes(color = Species))+
geom_smooth()

我得到的图表:

第一个代码的输出
enter image description here

输出第二个代码
enter image description here

1 回答

  • 1

    这可能是因为第二种情况下的aes()调用会对点进行着色,但这并不会延伸到平滑线的颜色 . 更改第二个示例以向geom_smooth()调用添加对aes(color ...)的显式调用会产生与第一个示例相同的结果 .

    ggplot(aes(x = Sepal.Length, y = Petal.Length), data = trainData) +
    geom_point(aes(color = Species)) +
    geom_smooth(aes(color=Species))
    

相关问题