library(ggplot2)DATA110_Fernandez_Maira_Airquality_Assignment2
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
✔ lubridate 1.9.5 ✔ tibble 3.3.1
✔ purrr 1.2.2 ✔ tidyr 1.3.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")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
mean(airquality[,4])[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"))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 sourcep1`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
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")#provide the data sourcep2p3<-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"))p3p4<-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_grey(name= "Month", labels= c("May", "June", "July", "August", "September"))p4p5 <-airquality1 |>
ggplot(aes(x = Temp, y = Ozone, color=Ozone)) +
geom_point() +
labs(
x = "Temperature",
y = "Ozone",
title = "Scatterplot of Temperature and Ozone",
caption = "New York State Department of Conservation and the National Weather Service"
)p5Warning: Removed 37 rows containing missing values or values outside the scale range
(`geom_point()`).
This graph represents how the Ozone line deteriorates as the temperature rises. I tried to change the color but when I added red the graph change to red dotes, so I returned to the first version. I tried to do graph with the Wind and Temperature, but were confusing. I used the code that we practice in previous class, because after trying many times with different graphs, I could not make it, so I decided to use the one that I already know.