Histogram
Sample Dataset
Dataset for create a histogram plot.
Exercises
1. Basic Histogram:
2. Change Bin Width:
Plot a histogram of income
with a specific bin width (e.g., bin width of 5000). Experiment with different bin widths to see how they affect the histogram.
3. Change Fill Color:
4. Change Border Color:
5. Add Density Plot:
Overlay a density plot on top of a histogram of income
to observe both the histogram and the smoothed density line.
6. Facet Histogram by Gender:
Create a histogram of spending_score
and use facet_grid
to separate the histograms by gender
.
7. Facet Histogram by Region:
Create a histogram of income
and use facet_grid
to split it by region
to compare distributions across regions.
8. Change Theme:
9. Customize Fill by Gender:
Create a histogram of income
and fill the bars based on the gender
variable.
Solution:
10. Facet Histogram by Two Variables:
Create a histogram of spending_score
and use facet_grid(gender ~ region)
to create a grid of histograms by both gender
and region
.