# Nakafa Learning Content

> For AI agents: use [llms.txt](https://nakafa.com/llms.txt) for the site index. Markdown versions are available by appending `.md` to content URLs or sending `Accept: text/markdown`.

URL: https://nakafa.com/en/subjects/mathematics/statistics-foundations/histogram
Source: https://raw.githubusercontent.com/nakafaai/nakafa.com/refs/heads/main/packages/contents/material/lesson/mathematics/statistics-foundations/histogram/en.mdx

Learn histograms vs bar charts in statistics. Learn to visualize data distribution, interpret frequency patterns, and choose the right chart type.

---

## Introduction to Histograms

You've probably seen bar charts used to present data. Well, a histogram is a close relative of the bar chart, but it has a specific purpose. Let's compare the two so we understand their differences.

## Bar Chart vs Histogram

Bar charts are used for categorical data (such as phone brands or favorite sports):

Component: BarChart
Props:
- title: Bar Chart of Phone Brands Used by High School Students
- description: Shows the number of students per phone brand.
- data: [
{ name: "Apple", value: 12 },
{ name: "Samsung", value: 10 },
{ name: "Xiaomi", value: 8 },
{ name: "Oppo", value: 5 },
{ name: "Lenovo", value: 5 },
]
- chartConfig: {
value: {
label: "Number of Students",
colors: {
light: ["var(--chart-1)", "var(--chart-2)", "var(--chart-3)", "var(--chart-4)", "var(--chart-5)"],
dark: ["var(--chart-1)", "var(--chart-2)", "var(--chart-3)", "var(--chart-4)", "var(--chart-5)"],
},
},
}
- yAxisLabel: Number of Students

In the bar chart above:

- Apple is the most used brand ($$12$$ students)
- Samsung is in second place ($$10$$ students)
- Xiaomi is in third place ($$8$$ students)
- Oppo and Lenovo are both used by $$5$$ students each

Visible text: - Apple is the most used brand ( students)
- Samsung is in second place ( students)
- Xiaomi is in third place ( students)
- Oppo and Lenovo are both used by students each

Notice that each bar is **separated** from the others because they represent different categories.

Histograms, on the other hand, are used for numerical data grouped into intervals, such as time duration or height. The bars touch each other because the intervals of values are continuous.

Component: HistogramChart
Props:
- title: Histogram of Mobile Phone Usage by High School Students
- description: Shows the distribution of time students spend on their phones daily.
- data: [
{ name: "0-2", value: 10 },
{ name: "2-4", value: 12 },
{ name: "4-6", value: 32 },
{ name: "6-8", value: 28 },
{ name: "8-10", value: 8 },
]
- chartConfig: {
value: {
label: "Frequency",
colors: {
light: ["var(--chart-1)", "var(--chart-2)", "var(--chart-3)", "var(--chart-4)", "var(--chart-5)"],
dark: ["var(--chart-1)", "var(--chart-2)", "var(--chart-3)", "var(--chart-4)", "var(--chart-5)"],
},
},
}
- yAxisLabel: Frequency

From the histogram above, we can see the pattern of phone usage among high school students:

- $$10$$ students use their phones for $$0\text{-}2 \text{ hours}$$ per day
- $$12$$ students use their phones for $$2\text{-}4 \text{ hours}$$ per day
- The highest number is $$32$$ students who use their phones for $$4\text{-}6 \text{ hours}$$ per day
- $$28$$ students use their phones for $$6\text{-}8 \text{ hours}$$ per day
- $$8$$ students use their phones for $$8\text{-}10 \text{ hours}$$ per day

Visible text: - students use their phones for per day
- students use their phones for per day
- The highest number is students who use their phones for per day
- students use their phones for per day
- students use their phones for per day

From this data, we can conclude that the majority of students use their phones between $$4\text{-}8 \text{ hours}$$ per day, with the peak in the $$4\text{-}6 \text{ hours}$$ range.

Visible text: From this data, we can conclude that the majority of students use their phones between per day, with the peak in the range.

## Key Differences

| Difference   | Histogram                            | Bar Chart                                   |
| ------------ | ------------------------------------ | ------------------------------------------- |
| Type of data | Quantitative, grouped into intervals | Categorical, each bar for a single category |
| Bar shape    | Bars touch each other, no gaps       | Spaces between bars                         |
| Bar width    | Bar area represents frequency        | Equal width, bar height shows quantity      |

Visible text: | Difference | Histogram | Bar Chart |
| ------------ | ------------------------------------ | ------------------------------------------- |
| Type of data | Quantitative, grouped into intervals | Categorical, each bar for a single category |
| Bar shape | Bars touch each other, no gaps | Spaces between bars |
| Bar width | Bar area represents frequency | Equal width, bar height shows quantity |

## When to Use a Histogram?

Use a histogram when:

1. Data consists of measurable numbers (quantitative)
2. You want to see the distribution or spread of data
3. Data can be grouped into intervals

Examples of data suitable for histograms:

- Student heights
- Test scores
- Travel time to school
- Body weight
- Device usage time

Histograms are very useful for viewing patterns in numerical data distribution. With histograms, we can identify the most frequent values, dominant value ranges, and the shape of data distribution (even, skewed left/right, or centered in the middle).