gpt4 book ai didi

r - Geom_line 和 fill 在 ggplot 中不能一起使用

转载 作者:行者123 更新时间:2023-12-02 02:53:00 25 4
gpt4 key购买 nike

似乎 geom_line 会干扰 aes(fill=),因为:

ggplot(iris, aes(Sepal.Width, Sepal.Length,
fill = Petal.Width))+
geom_point(shape = 21)+
scale_fill_gradient(low="orange",high="blue")+
geom_line(aes(cyl, am), mtcars)

给我:

Error in FUN(X[[i]], ...) : object "Petal.Width" not found

有什么解释吗?

最佳答案

您需要使第二个图的 fill 无效,因为 mtcars 没有 Petal.Width 变量。

library(ggplot2)
ggplot(iris, aes(Sepal.Width, Sepal.Length,
fill = Petal.Width))+
geom_point(shape = 21)+
scale_fill_gradient(low="orange",high="blue")+
geom_line(aes(cyl, am, fill=NULL), mtcars)

关于r - Geom_line 和 fill 在 ggplot 中不能一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61633231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com