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:
Syntax
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()
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")
Login to try C/C++/Java/PHP code in the editor
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
- Passing a whole data frame with non-numeric columns, when
boxplot()needs numeric data or a formula. - Treating dots beyond the whiskers as errors, when they are marked outliers.
- Using
boxplot(y ~ group)in the wrong order, such asgroup ~ y, so the plot is wrong.
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: