I am trying to plot some data from my experiment in R using ggplot2
, and I am trying to split the graph in two parts using facet_grid()
.
Here is an MWE I built with the cars dataset:
data(mtcars)
ggplot(data=mtcars, aes(x=mtcars$mpg,y=mtcars$cyl)) +
geom_point()+
facet_grid(rows=mtcars$disp)
I get the following error:
Error in facet_grid(rows = mtcars$disp) :
unused argument (rows = mtcars$disp)
I really have no idea why this is happening. I used this function before, and it worked fine. Would appreciate ideas on how to solve this.
edit: I accepted the second answer, because it provides some more context, but as I see it, both are equally correct in pointing out that I need to quote the variable name. The actual error was resolved after installig R and all packages again. Now I have a new error, but that is another story. Thanks again!