# R Boxplot

Boxplots are a measure of how well data is distributed across a data set. This divides the data set into three quartiles. This graph represents the minimum, maximum, average, first quartile, and the third quartile in the data set. Boxplot is also useful in comparing the distribution of data in a data set by drawing a boxplot for each of them.

R provides a boxplot() function to create a boxplot. There is the following syntax of boxplot() function:

Here,

S.No Parameter Description
1. x It is a vector or a formula.
2. data It is the data frame.
3. notch It is a logical value set as true to draw a notch.
4. varwidth It is also a logical value set as true to draw the width of the box same as the sample size.
5. names It is the group of labels that will be printed under each boxplot.
6. main It is used to give a title to the graph.

Let?s see an example to understand how we can create a boxplot in R. In the below example, we will use the "mtcars" dataset present in the R environment. We will use its two columns only, i.e., "mpg" and "cyl". The below example will create a boxplot graph for the relation between mpg and cyl, i.e., miles per gallon and number of cylinders, respectively.

### Example

Output: ## Boxplot using notch

In R, we can draw a boxplot using a notch. It helps us to find out how the medians of different data groups match with each other. Let's see an example to understand how a boxplot graph is created using notch for each of the groups.

In our below example, we will use the same dataset ?mtcars."

### Example

Output: ## Violin Plots

R provides an additional plotting scheme which is created with the combination of a boxplot and a kernel density plot. The violin plots are created with the help of vioplot() function present in the vioplot package.

Let's see an example to understand the creation of the violin plot.

### Example

Output: ## Bagplot- 2-Dimensional Boxplot Extension

The bagplot(x, y) function in the aplpack package provides a biennial version of the univariate boxplot. The bag contains 50% of all points. The bivariate median is approximate. The fence separates itself from the outside points, and the outlays are displayed.

Let?s see an example to understand how we can create a two-dimensional boxplot extension in R.

### Example

Output: Next TopicR Histogram   