> For the complete documentation index, see [llms.txt](https://til.kurianbenoy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.kurianbenoy.com/r-programming-language/facet_grid-and-facet_wrap.md).

# Facet\_grid and Facet\_wrap

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

![](/files/-MjQGylE71RfjMF0nkes)

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

![](/files/-MjQIeskuedlg9VWSP6y)

**Using facet\_grid**

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

![](/files/-MjQJcwJjxP8As6IjoSf)

**Using facet\_wrap**

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

![](/files/-MjQKps19swnGKxpArKU)

**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**

{% embed url="<https://www.datacamp.com/community/tutorials/facets-ggplot-r>" %}

Dr Ebin Sir's tidverse tutorials
