← Back to R Course | Chapter 10: Data Visualization | Lesson 4 of 7

boxplot()

A boxplot shows the middle, the spread, and the oddballs of a set of numbers in one small picture. It is like a quick photo of how a group of scores looks.

In this page:

  1. boxplot()
Syntax
r
boxplot(x, main = "title")
boxplot(value ~ group, data = df)

boxplot()

boxplot(x) summarizes a numeric vector's distribution visually through its quartiles, median, and outliers, using the same five-number summary as summary().

It's especially useful for comparing distributions across several groups side by side, like boxplot(value ~ group, data = df). Boxplots make outliers immediately visible as points beyond the plot's whiskers.

Note: boxplot(value ~ group, data = df) draws one box per group, making it easy to compare distributions side by side.

Example: boxplot()

markup
set.seed(1)
values <- c(rnorm(20, mean = 50), 150)  # includes an outlier

print(summary(values))
cat("boxplot(values) would show the outlier at 150 clearly beyond the whiskers\n")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Passing a whole data frame with non-numeric columns, when boxplot() needs numeric data or a formula.
  2. Treating dots beyond the whiskers as errors, when they are marked outliers.
  3. Using boxplot(y ~ group) in the wrong order, such as group ~ y, so the plot is wrong.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.