Error in geom_point() : could not find function "geom_point"

Hi Everyone,

I'm brand new to RStudio and unable to run some initial code. Seems like maybe something did not install correctly, but no solutions I've found have helped. When I try to plot a dataset, the following code results in the following error:

ggplot(data=mydata,
aes=(x=carat, y=price, colour=clarity)) +
geom_point() +
geom_smooth()

Error in geom_point() : could not find function "geom_point"

Did you load the ggplot2 package with:

library(ggplot2)

If you paste more of your script it could help someone figure out what's going on. Also it's hard for us to tell what mydata refers to. If you saved the diamonds dataset to mydata, then this should work if ggplot2 is loaded. But if mydata has different variables in it (instead of carat, price, clarity) you would need to update those mappings.

You may not have loaded the library or the data.frame mydata does not exist
Try

library(ggplot2)

##rest of code

Also just an observation that you used aes=(stuff) which should be mapping = aes(stuff) (and really in ggplot you can get away with omitting both data= and mapping=).

If you haven't come across it already, you will find https://r4ds.had.co.nz/ especially https://r4ds.had.co.nz/data-visualisation.html very helpful.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.