## What are Facets?

- Facets are a way to create multiple small plots within a single larger plot.
- Let’s you reorganize your data and show relationships between variables

Facet functions let you display smaller groups, or subsets, of your data. - Faucets show each side of the data by placing subsets on its own plot.
- Facets can help you discover new patterns in subsets of a dataset
- Facets can focus relationships between different variables

## Functions for Faceting

### facet_wrap()

For example, here we are comparing the raltionship between flipper length and body mass and then they will be compared to the various species.

The + symbol adds a new layer to the code.

Type a ’tilde’ (~) symbol and the variable to be used as an argument in the facet_wrap() function.

The *facet_wrap *is actually a function that is being called to separate and distribute the independent data within the plot.

In the case of our example below, facet_wrap is the dependent variable and species the independent variable.

ggplot(data = penguin) +

mapping = aes(x=flipper_length_mm, y=body_mass_g, color=species)) +

facet_wrap(~species)

faucet_grid()

### What is facet_grid()?

facet_grid() is a function in ggplot2 that allows you to create a grid of small plots based on two or more categorical variables. It essentially lets you split your data into subsets and create individual plots for each combination of categories. This can be immensely helpful when you want to explore the relationships and patterns within your data for different subgroups.

`library(ggplot2)`

ggplot(data, aes(x = x_var, y = y_var)) +

geom_point() +

facet_grid(rows ~ columns)

Definitions:

A Tilde operator is used to define the relationship between dependent variable and independent variables in a statistical model formula. Type a ’tilde’ (~) symbol and the variable to be used as an argument in the facet_wrap() function.

The variable on the left-hand side of tilde operator is the dependent variable and the variable(s) on the right-hand side of tilde operator is/are called the independent variable(s). So, tilde operator helps to define that dependent variable depends on the independent variable(s) that are on the right-hand side of tilde operator. (retrieved from tutorialspoint.com)