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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With