p1 <- airquality |>ggplot(aes(x=Temp, fill=Month)) +geom_histogram(position="identity")+scale_fill_discrete(name ="Month", labels =c("May", "June","July", "August", "September")) +labs(x ="Monthly Temperatures from May - Sept", y ="Frequency of Temps",title ="Histogram of Monthly Temperatures from May - Sept, 1973",caption ="New York State Department of Conservation and the National Weather Service") #provide the data source
Plot 1 Output
p1
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Plot 2: Improve the histogram of Average Temperature by Month
p2 <- airquality |>ggplot(aes(x=Temp, fill=Month)) +geom_histogram(position="identity", alpha=0.5, binwidth =5, color ="white")+scale_fill_discrete(name ="Month", labels =c("May", "June","July", "August", "September")) +labs(x ="Monthly Temperatures from May - Sept", y ="Frequency of Temps",title ="Histogram of Monthly Temperatures from May - Sept, 1973",caption ="New York State Department of Conservation and the National Weather Service")
Plot 2 output
p2
Plot 3: Create side-by-side boxplots categorized by Month
p3 <- airquality |>ggplot(aes(Month, Temp, fill = Month)) +labs(x ="Months from May through September", y ="Temperatures", title ="Side-by-Side Boxplot of Monthly Temperatures",caption ="New York State Department of Conservation and the National Weather Service") +geom_boxplot() +scale_fill_discrete(name ="Month", labels =c("May", "June","July", "August", "September"))
Plot 3 output
p3
Plot 4: Side by Side Boxplots in Gray Scale
p4 <- airquality |>ggplot(aes(Month, Temp, fill = Month)) +labs(x ="Monthly Temperatures", y ="Temperatures", title ="Side-by-Side Boxplot of Monthly Temperatures",caption ="New York State Department of Conservation and the National Weather Service") +geom_boxplot()+scale_fill_grey(name ="Month", labels =c("May", "June","July", "August", "September"))
Plot 4 output
p4
Plot 5: Scatterplot of Ozone and Wind
p5 <-ggplot(airquality, aes(x = Wind, y = Ozone, color = Month)) +geom_point(size =2, alpha =0.7) +labs(title ="Scatterplot of Ozone and Wind by Month",x ="Wind Speed (mph)",y ="Ozone (ppb)",caption ="Data Source: New York State Department of Conservation and the National Weather Service" ) +theme_minimal()
Plot 5 output
p5
Warning: Removed 37 rows containing missing values or values outside the scale range
(`geom_point()`).
This is a scatterplot that displays the relationship between Wind and Ozone levels. Points are colored based on the Month, using the factor levels from May to September.
The plot suggests that higher wind speeds tend to be associated with lower ozone levels, especially visible in July and August. It also shows month-by-month clustering, which could be related to seasonal effects on air quality.
Special Code Used:
theme_minimal() gives the plot a clean, readable appearance.