Airquality Assignment

Author

Sephora Apeti

library(tidyverse)
data("airquality")
head(airquality)
  Ozone Solar.R Wind Temp Month Day
1    41     190  7.4   67     5   1
2    36     118  8.0   72     5   2
3    12     149 12.6   74     5   3
4    18     313 11.5   62     5   4
5    NA      NA 14.3   56     5   5
6    28      NA 14.9   66     5   6
mean(airquality$Temp)
[1] 77.88235
median(airquality$Temp)
[1] 79
sd(airquality$Wind)
[1] 3.523001
var(airquality$Wind)
[1] 12.41154
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"))
summary(airquality1$month_name)
   Length  N.unique   N.blank Min.nchar Max.nchar 
      153         5         0         3         9 
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, 1973", caption = "New York State Department of Conservation and the National Weather Service")
p2

{style="font-size:65%;"}

##plot3

p3 <- airquality1 |>
  ggplot (aes(Month, Temp, fill = month_name)) + labs (x = "Months from May through September", y = "temparatures", 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

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: Scatterplot of Wind Speed and Temperature

p5 <- airquality1 |> 
  ggplot(aes(x = Day, y = Wind, color = Month )) + geom_point(size = 2, alpha = 0.7) + geom_smooth(method = "lm", se = FALSE, color = "black") + labs(x = "Wind Speed", y = "Day", title = "Relationship Between Wind Speed and Day", caption = "New York State Department of Conservation and the National Weather Service", color = "Month") + theme_minimal()
p5
`geom_smooth()` using formula = 'y ~ x'

For plot 5 I created a scatter plot showing the relationship between wind speed and day in the dataset. The x-axis shows the wind speed and the y-axis shows the day.The plot shows how wind speed varies across different days from May through September. The points are colored by month, which makes it easier to compare wind patterns across the five months. The trend line shows the overall relationship between day of the month and wind speed. For this plot, I used `geom_point() to create the scatterplot and geom_smooth() to add a trend line. I also used color = Month to color the points by month and theme_minimal() to give the graph a cleaner appearance.