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 sourcep1
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Plot 2: Improved Histogram
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")p2
Plot 3: Side by Side Boxplots
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"))p3
Plot 4: Grayscale Boxplots
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"))p4
Plot 5:
airquality |>ggplot(aes(x = Month, y = Ozone, fill = Month)) +labs(x ="Months, May to September 1973", y ="Ozone Level (ppb)",title="Side by Side Boxplot of Monthly Ozone Levels",caption ="New York State Department of Conservation and the National Weather Service") +geom_boxplot()
Warning: Removed 37 rows containing non-finite outside the scale range
(`stat_boxplot()`).
Essay
I chose to demonstrate ozone levels by month using boxplots. With this visualization, I notice ozone levels were much higher on average in July and August than the other months. These months had a much wider range with maximum values at around 125 ppb. Meanwhile, excluding outliers, average ozone levels didn’t even reach 50 ppb in May, June, and September. This may be due to increased travel over the summer or other factors that require further research. Side-by-side boxplots provide a simple way to visualize ozone levels and its changes throughout the months.