6

I am trying to learn ggplot with facet. here is the codes works in Rstudio

p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()

  # With one variable
p + facet_grid(. ~ cyl)

however, it shows error for ncol after I added ncol=2 :

    p + facet_grid( ~ cyl,ncol=2)

Error in facet_grid(~cyl, ncol = 2) : unused argument (ncol = 2)
zx8754
  • 52,746
  • 12
  • 114
  • 209
czqiu
  • 291
  • 1
  • 3
  • 7

1 Answers1

8
#use facet_wrap
p + facet_wrap( ~ cyl, ncol = 2)
Metrics
  • 15,172
  • 7
  • 54
  • 83