1 + 1
[1] 2
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1 + 1
[1] 2
You can add options to executable code like this
[1] 4
The echo: false
option disables the printing of code (only output is displayed).
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.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
median(airquality$Temp)
[1] 79
sd(airquality$Wind)
[1] 3.523001
var(airquality$Wind)
[1] 12.41154
$Month[airquality$Month==5]<-"May"
airquality$Month[airquality$Month==6]<-"June"
airquality$Month[airquality$Month==7]<-"July"
airquality$Month[airquality$Month==8]<-"August"
airquality$Month[airquality$Month==9]<-"September" airquality
summary(airquality$Month)
Length Class Mode
153 character character
$Month<-factor(airquality$Month,
airqualitylevels=c("May","June","July","August"
"September")) ,
<-airquality |>
p1 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")
p1
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
<- airquality |>
p2 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
<- airquality |>
p3 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
<- airquality |>
p4 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
<- airquality |>
p5 ggplot(aes(Month, Wind, fill = Month)) +
labs(x = "Months from May-September", y = "Wind Rates",
title = "Boxplot of Monthly Wind Rates",
caption = "New York State Department of Conservation and the National Weather Service") +
geom_boxplot() +
scale_fill_brewer(name = "Month", labels = c("May", "June","July", "August", "September"))
p5
The type of plot that I have created is a boxplot that shows the wind rates from May to September. The color coordination shows the wind rates for each month, and you are able to see the vertical spread for each month. The boxplots allow you to see the approximate five number summary for each boxplot, but for a quick glance you are able to see the months that have a larger spread and where the 50% of data lies for each month. This is helpful for learning which months have higher and lower rates of wind. In order to get the cohesive colors that get darker for each month, I was able to use “scale_fill_brewer” instead of the default that replaces “brewer” with “discrete”.