Histogram and Density Plots
📖 Scenario: You are a data analyst working with a small dataset of daily temperatures. You want to understand how the temperatures are distributed by creating a histogram and a density plot.
🎯 Goal: Build an R script that creates a vector of temperature data, sets a bin width for the histogram, generates both a histogram and a density plot using base R plotting functions, and then displays the plots.
📋 What You'll Learn
Create a numeric vector called
temperatures with the exact values: 22, 25, 19, 24, 30, 28, 21, 23, 27, 26Create a numeric variable called
bin_width and set it to 3Use the
hist() function with breaks=seq() to create a histogram of temperatures with bins of width bin_widthUse the
plot() function with density() to create a density plot of temperaturesPrint both plots so they are visible
💡 Why This Matters
🌍 Real World
Histograms and density plots help you understand how data points are spread out, which is useful in weather analysis, sales data, or any measurements.
💼 Career
Data analysts and scientists use these plots to explore data distributions before making decisions or building models.
Progress0 / 4 steps