R 为什么ggplot中的此命令返回错误?

R 为什么ggplot中的此命令返回错误?,r,ggplot2,layer,R,Ggplot2,Layer,我正在学习ggplot2,我不明白为什么这不起作用: p <- ggplot(diamonds, aes(x = carat)) p <- p + layer( geom = "point", stat = "identity" ) p Error in as.environment(where) : 'where' is missing p通常不使用图层建立绘图。而是使用geom或statp+geom_point()将绘制您要查找的内容。我建议您研究一下gpl

我正在学习ggplot2,我不明白为什么这不起作用:

p <- ggplot(diamonds, aes(x = carat))
p <- p + layer(
     geom = "point",
     stat = "identity"
)
p
Error in as.environment(where) : 'where' is missing

p通常不使用
图层
建立绘图。而是使用
geom
stat
p+geom_point()
将绘制您要查找的内容。我建议您研究一下
gplot2
文档中的一些示例。

我认为问题在于您没有指定y值使用什么。ggplot2的默认值与根据索引值打印点的基本图形不同。要将
geom_point()
stat=“identity”
一起使用,您需要以下内容:

p<-ggplot(diamonds, aes(x=carat, y=cut))
p+layer(geom="point", stat="identity")

或者你想尝试绘制你的数据。

没错,但通过使用图层,我只是想了解geom和stat到底是什么,以及它们是如何相互作用的。将你的数据和美学移到
图层
调用会给你一个原型对象,但我不知道该怎么处理:
图层(数据=钻石,aes(x=插入符号),geom='point',stat='identity')
。然而,
stat='identity'
在这里是多余的。
p+geom_point(stat="identity")