Next →

Output:


      

Plots:

Boxplots

Boxplots are used to visualize the distribution of numerical data and identify outliers. They display the median, quartiles, and potential outliers. In R, you can create boxplots using the base boxplot() function or ggplot2.

Basic Boxplot

# Sample data
values <- c(5, 7, 8, 5, 6, 7, 8, 9, 5, 6)

# Create a boxplot
boxplot(values, main = "Basic Boxplot", ylab = "Values", col = "lightgreen")

Using ggplot2

library(ggplot2)

df <- data.frame(values = values)

ggplot(df, aes(y = values)) +
  geom_boxplot(fill = "purple", color = "black") +
  ggtitle("Boxplot with ggplot2") +
  theme_minimal()

Boxplots are particularly useful for comparing distributions across multiple groups and spotting outliers.