# R Programming language - R BoxPlot

In R, you can create a box plot using the `boxplot()`

function. A box plot is a graphical representation of a dataset's distribution through five key summary statistics: minimum, first quartile, median, third quartile, and maximum. The box portion of the plot represents the middle 50% of the data, while the whiskers extend to the minimum and maximum values.

Here is a basic example of how to create a box plot in R:

# Create a vector of values to plot values <- c(10, 20, 30, 40, 50) # Create a box plot of the values boxplot(values)

This will create a simple box plot with the five summary statistics and outliers, if any.

You can customize the appearance of the box plot by using the optional arguments of the `boxplot()`

function. For example, you can add labels to the x-axis and y-axis using the `xlab`

and `ylab`

arguments:

# Create a box plot of the values with custom labels boxplot(values, xlab = "X-axis label", ylab = "Y-axis label")

You can also change the colors of the boxes, whiskers, and outliers using the `col`

argument:

# Create a box plot of the values with custom colors boxplot(values, col = c("red", "green"), outlier.col = "blue")

You can also create a grouped box plot with multiple datasets by passing a list of vectors to the `boxplot()`

function:

# Create a grouped box plot of multiple datasets data1 <- c(10, 20, 30, 40, 50) data2 <- c(20, 30, 40, 50, 60) boxplot(list(data1, data2))