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?
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.
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.
layer call gives you a proto object back, but I don't know what to do with it: layer(data=diamons, aes(x=caret), geom='point', stat='identity'). However, stat='identity' is rather redundant here.