【发布时间】:2013-06-25 15:54:06
【问题描述】:
我正在学习 ggplot2,但我不明白为什么这不起作用:
p <- ggplot(diamonds, aes(x = carat))
p <- p + layer(
geom = "point",
stat = "identity"
)
p
Error in as.environment(where) : 'where' is missing
你知道为什么吗?
【问题讨论】:
我正在学习 ggplot2,但我不明白为什么这不起作用:
p <- ggplot(diamonds, aes(x = carat))
p <- p + layer(
geom = "point",
stat = "identity"
)
p
Error in as.environment(where) : 'where' is missing
你知道为什么吗?
【问题讨论】:
我认为问题在于您没有指定 y 值的用途。 ggplot2 没有与基本图形相同的默认值,用于根据索引值绘制点。要将 geom_point() 与 stat="identity" 一起使用,您需要以下内容:
p<-ggplot(diamonds, aes(x=carat, y=cut))
p+layer(geom="point", stat="identity")
或更常见
p+geom_point(stat="identity")
或者你想尝试绘制你的数据。
【讨论】:
通常您不会使用layer 来构建情节。相反,您使用geom 或stat。 p + geom_point() 将绘制您要查找的内容。我建议通过 gplot2 文档中的一些示例。
【讨论】:
layer 调用中会给您一个原始对象,但我不知道如何处理它:layer(data=diamons, aes(x=caret), geom='point', stat='identity')。但是,stat='identity' 在这里显得有些多余。