Assignment 2 HW

Assignment 2 HW

Github Profile:

https://github.com/Terry4569

Plot 1

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") 
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
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 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, Temp, fill = month_name)) + 
  labs(x = "Months from May through September", 
       y = "Temperatures", 
       title = "Dot Plot of Monthly Temperatures",
       caption = "National Weather Service") +
  geom_dotplot(binaxis = "y", 
               stackdir = "center") +
  scale_fill_grey(name = "Month", 
                  labels = c("May", "June", "July", "August", "September"))

p5
Bin width defaults to 1/30 of the range of the data. Pick better value with
`binwidth`.

Essay:

The plot I made describes the monthly temperatures through May and September. The type of chart created was a dotplot briefly describing the statistical reports of temperatures in each listed month. The dot plot given shows the report of monthly temperatures running from May to September from the code geom_dotplot. 

In order to create my own plot I decided to make a dotplot to describe the temperatures differently than the histogram or boxplots. I thought the idea of creating a dotplot would share the data in a unique way. It would’ve been an easier method for some people to understand what story it’s trying to tell. Based on what the plot is saying is that the temperature in May had the lowest out of the months down to 60. As the months went by the temperatures got higher from 80 to 90 by September. The plot overall shows a temperature increase. As the months go by, the variables rise. The method of creating the plot was simple. I used “ggplot” to create the plot and selected the variables Month and Temp from my dataset. I put Month on the x-axis and Temperature on the y-axis. Then I used geom_dotplot to display the temperature values as dots, making it easier to see how temperatures were distributed across the months. As a result, that gave me the dotplot I needed to present my information.

In conclusion, I used a dotplot that tells how the temperatures during each month increased by using the coding method geom_dotplot for my chart. Just like any chart used in the previous plot this gives me a distinctive point of view of what the data is trying to say. Therefore, the given dotplot is another helpful way to spread information to tell its story and what kind of codes to use when they need a specific plot style.