Histogram
Sample Dataset
Tip Dataset for create a histogram plot.
Exercises
Note 1. Basic Histogram:
Note 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.
Note 3. Change Fill Color:
Note 4. Change Border Color:
Note 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.
Note 6. Facet Histogram by Gender:
Create a histogram of spending_score
and use facet_grid
to separate the histograms by gender
.
Note 7. Facet Histogram by Region:
Create a histogram of income
and use facet_grid
to split it by region
to compare distributions across regions.
Note 8. Change Theme:
Note 9. Customize Fill by Gender:
Create a histogram of income
and fill the bars based on the gender
variable.
Solution:
Note 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
.