# 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.kurianbenoy.com/r-programming-language/facet_grid-and-facet_wrap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
