Reputation: 2426
I'm learning ggplot2 and I don't understand why this doesn't work :
p <- ggplot(diamonds, aes(x = carat))
p <- p + layer(
geom = "point",
stat = "identity"
)
p
Error in as.environment(where) : 'where' is missing
Do you know why?
Upvotes: 8
Views: 5311
Reputation: 138
I think the problem is that you haven't specified what to use for the y-values. ggplot2 doesn't have the same default as the base graphics for plotting points against their index values. To use geom_point()
with stat="identity"
you'd need something like:
p<-ggplot(diamonds, aes(x=carat, y=cut))
p+layer(geom="point", stat="identity")
or more commonly
p+geom_point(stat="identity")
or however else you want try to plot your data.
Upvotes: 7
Reputation: 43255
Generally you don't use layer
to build up a plot. Instead, you use geom
or stat
. p + geom_point()
will plot what you're looking for. I'd suggest working through some of the examples in the gplot2
documentation.
Upvotes: 2