hist()
A histogram groups numbers into ranges and draws a bar for how many fall in each, like stacking blocks by height groups. It shows the shape of your data.
In this page:
Syntax
hist(x, breaks = number_of_bins, main = "title", xlab = "label")
hist()
hist(x) draws a histogram showing the frequency distribution of a numeric vector, automatically choosing sensible bin widths (or accept an explicit breaks argument).
It's one of the fastest ways to visually inspect a dataset's distribution shape. Histograms are a first step in exploratory data analysis for any numeric variable.
Note:
Pass breaks = n to hist() to control roughly how many bins the histogram uses.
Example: hist()
set.seed(1)
values <- rnorm(100, mean = 50, sd = 10)
cat("Summary of values that hist() would visualize:\n")
print(summary(values))
cat("hist(values) would draw a histogram of this distribution\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 data frame or a character vector, which gives
x must be numeric. - Reading the number of bars as data, when it depends on the
breakssetting and can hide the shape. - Confusing
hist()withbarplot(), when a histogram groups a numeric range into bins.
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: