Here is a first attempt at viewing a histogram of temperature by the months May through September. We will see that temperatures increase over these months. The median temperature appears to be about 75 degrees.
Reorder the legend so that it is not the default (alphabetical), but rather in chronological order.
fill = Month colors the histogram by months between May - Sept.
scale_fill_discrete(name = “Month”…) provides the month names on the right side as a legend.
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`.
Is this plot useful in answering questions about monthly temperature values? Yes
Plot 2: Improve the histogram using ggplot
Outline the bars in white using the color = “white” command
Use alpha to add some transparency (values between 0 and 1)
Change the binwidth
Histogram of Average Temperature by Month
Add some transparency and white borders around the histogram bars. Here July stands out for having high frequency of 85 degree temperatures. The dark purple color indicates overlaps of months due to the transparency.
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
Did this improve the readability of the plot? Yes
Plot 3: Create side-by-side boxplots categorized by Month
We can see that August has the highest temperatures based on the boxplot distribution.
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: Make the same side-by-side boxplots, but in grey-scale
Use the scale_fill_grey command for the grey-scale legend, and again, use fill=Month in the aesthetics
Side by Side Boxplots in Gray Scale
Here we just changed the color palette to gray scale using scale_fill_grey
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: Side-by-side box plot categorized by Monthly wind from May through September.
p5 <- airquality |>ggplot(aes(Month, Wind, fill = Month)) +labs(x ="Months from May through September", y ="Wind", title ="Side-by-Side Boxplot of Monthly Wind",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"))p5
Essay: The Box plot above shows distribution of wind speed from the month of May through September. The plot shows that the month of May registered the highest speed of wind distribution through the course of the month followed by September. Also, you notice that there are outliers above and below the month of June.The outliers could be an indication of the possibility of wind gusts during the month of June which would result in abnormalities of the data. The code used for this modification is as follows;
p5 <- airquality |> ggplot(aes(Month, Wind, fill = Month)) + labs(x = “Months from May through September”, y = “Wind”, title = “Side-by-Side Boxplot of Monthly Wind”, 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”)) p5