# Facet\_grid and Facet\_wrap

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

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-MjQE91sN2WBKfSzeJdN%2F-MjQGylE71RfjMF0nkes%2Fimage.png?alt=media\&token=82f2a924-1818-41be-8536-ebc6ef5ad533)

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

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-MjQE91sN2WBKfSzeJdN%2F-MjQIeskuedlg9VWSP6y%2Fimage.png?alt=media\&token=dac89413-9b6f-4d53-86d3-2f06d9ec98aa)

**Using facet\_grid**

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

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-MjQE91sN2WBKfSzeJdN%2F-MjQJcwJjxP8As6IjoSf%2Fimage.png?alt=media\&token=cc548d41-0c9d-4978-b86e-fa051931c09a)

**Using facet\_wrap**

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

![](https://4253921594-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MhiOx8KkYnYxHHqfUbB%2F-MjQE91sN2WBKfSzeJdN%2F-MjQKps19swnGKxpArKU%2Fimage.png?alt=media\&token=167bf8a6-22e7-4033-bf44-9e3e4c06a75f)

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