What's the difference between facet_wrap() and facet_grid() in ggplot2?

前端 未结 4 1220
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 01:31

I\'ve been reading the ggplot2 documentation for both functions. I was wondering what were the differences and what would be right situation for using each func

4条回答
  •  我在风中等你
    2020-12-13 02:14

    facet_wrap(...) strings together ggplots in different frames (facets) based in a single variable. facet_grid(...) can take two variables:

    p + facet_grid(cyl~class)
    

    You can also use a third variable to group in each facet:

    qplot(displ, hwy, data=mpg,color=factor(year)) + facet_grid(cyl~class)
    

    shows the improvement (or lack thereof) in hwy mileage vs. displacement by #cylinders and class.

提交回复
热议问题