Facet_grid and Facet_wrap

ramblings on using ggplot

How to create wonderful visualizations in R like the below with multiple panel plots?

Facetting - can be consider as a method to create multiple panel plots based on splitting attributes which we decide.

Using facet_grid

ggplot(gapminder, aes(x=continent, y=gdpPercap))
 + geom_bar(stat = 'identity', fill='forest green')
   + facet_wrap(~year)

Using facet_wrap

ggplot(gapminder, aes(x=pop)) + geom_density() +
 facet_wrap(~year) + scale_x_log10()

Main difference I noticed was:

*facet_wrap* was working only for a single varaibles, but to create a multple plot in two dimension we had to used *facet-grid*

Reference

Dr Ebin Sir's tidverse tutorials

Last updated