AirqualityHW

Author

Evan

library("tidyverse")
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data("airquality")


airquality1 <- airquality |>
  mutate(month_name = case_when(Month == 4 ~ "April",
                                Month == 5 ~ "May",
                                Month == 6 ~ "June",
                                Month == 7 ~ "July",
                                Month == 8 ~ "August",
                                Month == 9 ~ "September"))

airquality1$Month<-factor(airquality1$month_name, 
                         levels=c("May", "June","July", "August",
                                  "September"))

Plot 1

p1 <- airquality1 |>
  ggplot(aes(x=Temp, fill=month_name)) +
  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
p1
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.

Plot 2

p2 <- airquality1 |>
  ggplot(aes(x=Temp, fill=month_name)) +
  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

p3 <- airquality1 |>
  ggplot(aes(Month, Temp, fill =  month_name)) + 
  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

p4 <- airquality1 |>
ggplot(aes(Month, Temp, fill = month_name)) + 
  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

p5 <- airquality1 |> ggplot(aes(Month, Wind, fill = Month)) + geom_boxplot(alpha = .8, color = "darkgrey") + labs(x = "Monthly Wind Speeds" , y ="Wind Speeds" , title = "Side-by-Side BoxPlots of Monthly Wind Speeds") + scale_fill_discrete(name="Month", labels = c("May", "June", "July", "August", "September"))


p5

This plot is a boxplot showing the distribution of wind speed for each month. I created it using the ggplot(), geom_boxplot(), labs(), and scale_fill_discrete() functions. In ggplot(), I assigned Month to the x-axis, Wind to the y-axis, and used Month as the fill variable so that each monthly boxplot would have a different color.

In geom_boxplot(), I adjusted the transparency of the boxes by setting alpha = 0.8, making them 20% transparent. I also changed the border color of the boxplots to dark gray. The labs() function was used to add the title “Side-by-Side BoxPlots of Monthly Wind Speeds”, the x-axis label “Monthly Wind Speeds”, and the y-axis label “Wind Speeds.” Finally, scale_fill_discrete() was used to create a legend on the right side of the graph, with the legend title labeled “Month” and the legend entries shown as the month names.