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.4.4 ✔ 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
library(dplyr)
cps <- read.csv("cpsa.csv") %>%
select("year", "total.employed.labor.force", "total.unemployed.labor.force", "not.in.labor.force") %>%
rename(total_employed_lf = total.employed.labor.force) %>%
rename(total_unemployed_lf = total.unemployed.labor.force) %>%
rename(non_lf = not.in.labor.force) %>%
mutate(total_employed_lf = as.numeric(gsub(",", "", total_employed_lf)),
total_unemployed_lf = as.numeric(gsub(",", "", total_unemployed_lf)),
non_lf = as.numeric(gsub(",", "", non_lf)))
cpsa <- cps %>%
filter(year >= 2017)
covid <- read.csv("WHO-COVID-19-global-data.csv")
covid_use <- covid %>%
filter(Country == "United States of America") %>%
select("Date_reported", "Country_code", "New_cases", "New_deaths") %>%
mutate(New_cases = ifelse(is.na(New_cases), 0, New_cases)) %>%
mutate(New_deaths = ifelse(is.na(New_deaths), 0, New_deaths))
head(cpsa, 10)
## year total_employed_lf total_unemployed_lf non_lf
## 1 2017 153337 6982 94759
## 2 2018 155761 6314 95716
## 3 2019 157538 6001 95636
## 4 2020 147795 12947 99587
## 5 2021 152581 8623 100241
## 6 2022 158291 5996 99686
## 7 2023 161037 6080 99826
head(covid_use, 10)
## Date_reported Country_code New_cases New_deaths
## 1 2020-01-05 US 0 0
## 2 2020-01-12 US 0 0
## 3 2020-01-19 US 0 0
## 4 2020-01-26 US 7 0
## 5 2020-02-02 US 2 0
## 6 2020-02-09 US 11 0
## 7 2020-02-16 US 4 0
## 8 2020-02-23 US 16 0
## 9 2020-03-01 US 33 1
## 10 2020-03-08 US 391 18
library(dplyr)
## summarization data frame
## new categorical column
covid_case_average <- mean(covid$New_cases, na.rm = TRUE)
covid_death_average <- mean(covid$New_deaths, na.rm = TRUE)
covid_case_average
## [1] 21093.61
covid_death_average
## [1] 289.6709
covid_ave_df <- covid_use %>%
summarize(
date = Date_reported,
cases = New_cases,
ave_case_rate = ifelse(New_cases > covid_case_average, "above", "below"),
deaths = New_deaths,
ave_death_rate = ifelse(New_deaths > covid_death_average, "above", "below")
)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
## always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
head(covid_ave_df, 10)
## date cases ave_case_rate deaths ave_death_rate
## 1 2020-01-05 0 below 0 below
## 2 2020-01-12 0 below 0 below
## 3 2020-01-19 0 below 0 below
## 4 2020-01-26 7 below 0 below
## 5 2020-02-02 2 below 0 below
## 6 2020-02-09 11 below 0 below
## 7 2020-02-16 4 below 0 below
## 8 2020-02-23 16 below 0 below
## 9 2020-03-01 33 below 1 below
## 10 2020-03-08 391 below 18 below
## new numerical column
cpsa <- cpsa %>%
mutate(total_lf = total_employed_lf + total_unemployed_lf)
cpsa
## year total_employed_lf total_unemployed_lf non_lf total_lf
## 1 2017 153337 6982 94759 160319
## 2 2018 155761 6314 95716 162075
## 3 2019 157538 6001 95636 163539
## 4 2020 147795 12947 99587 160742
## 5 2021 152581 8623 100241 161204
## 6 2022 158291 5996 99686 164287
## 7 2023 161037 6080 99826 167117
library(dplyr)
covid_use$Date_reported <- as.Date(covid_use$Date_reported)
covid_use$year <- format(covid_use$Date_reported, "%Y")
covid_merge <- covid_use %>%
group_by(year) %>%
summarise(
total_case = sum(New_cases),
total_deaths = sum(New_deaths)
) %>%
filter(year != 2024) %>%
mutate(year = as.numeric(year))
cpsa <- cpsa %>%
mutate(year = as.numeric(year))
merge_df <- left_join(cpsa, covid_merge) %>%
mutate(total_case = ifelse(is.na(total_case), 0, total_case)) %>%
mutate(total_deaths = ifelse(is.na(total_deaths), 0, total_deaths))
## Joining with `by = join_by(year)`
merge_df
## year total_employed_lf total_unemployed_lf non_lf total_lf total_case
## 1 2017 153337 6982 94759 160319 0
## 2 2018 155761 6314 95716 162075 0
## 3 2019 157538 6001 95636 163539 0
## 4 2020 147795 12947 99587 160742 18890446
## 5 2021 152581 8623 100241 161204 32988414
## 6 2022 158291 5996 99686 164287 47140633
## 7 2023 161037 6080 99826 167117 4417336
## total_deaths
## 1 0
## 2 0
## 3 0
## 4 342920
## 5 469667
## 6 267389
## 7 83835
library(ggplot2)
## line plot for unemployment vs. covid cases
ggplot(merge_df, aes(x = total_case, y = total_unemployed_lf, color = year)) +
geom_line() +
geom_point(value = year) +
scale_color_gradient(low = "darkblue", high = "red") +
scale_x_continuous(labels = scales::comma) +
labs(
title = "Relationship Between COVID 19 Cases and Unemployement",
x = "Total COVID 19 Cases",
y = "Total Unemployement (in thousand)",
color = "Year"
)
## Warning in geom_point(value = year): Ignoring unknown parameters: `value`

## line plot for employment vs. covid cases
ggplot(merge_df, aes(x = total_case, y = total_employed_lf, color = year)) +
geom_line() +
geom_point(value = year) +
scale_color_gradient(low = "red", high = "blue") +
scale_x_continuous(labels = scales::comma) +
labs(
title = "Relationship Between COVID 19 Cases and Employement",
x = "Total COVID 19 Cases",
y = "Total Employement (in thousand)",
color = "Year"
)
## Warning in geom_point(value = year): Ignoring unknown parameters: `value`

## unemployement vs. employment
ggplot(cps, aes(x = total_employed_lf, y = total_unemployed_lf)) +
geom_point(size = 1, color = "red") +
geom_smooth(method = "lm", se = FALSE, size = 0.5, color = "black") +
labs(
title = "Relationship between Employment and Unemployment Over Time in America",
x = "Total Employment (in thousand)",
y = "Total Unemployement (in thousand)"
)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'

## barplot for confirmed cases
ggplot(covid_use, aes(x = Date_reported, y = New_cases)) +
geom_bar(stat = "identity", fill = "orange") +
scale_y_continuous(labels = scales::comma) +
labs(
title = "Confirmed COVID 19 Cases Over Time in America",
x = "Date",
y = "Confirmend Cases"
)

## barplot for death cases
ggplot(covid_use, aes(x = Date_reported, y = New_deaths)) +
geom_bar(stat = "identity", fill = "red") +
scale_y_continuous(labels = scales::comma) +
labs(
title = "COVID 19 Death Cases Over Time in America",
x = "Date",
y = "Death Cases"
)

## employed and unemployed status overtime
ggplot(merge_df, aes(x = year)) +
geom_line(aes(y = total_employed_lf, color = "Employed")) +
geom_point(aes(y = total_employed_lf, color = "Employed"), size = 2) +
geom_line(aes(y = total_unemployed_lf, color = "Unemployed")) +
geom_point(aes(y = total_unemployed_lf, color = "Unemployed"), size = 2) +
labs(
title = "Working Status in America 3 Years Before and After COVID 19",
x = "Year",
y = "Population (in thousand)",
color = "Status"
)

## cases status flow overtime
ggplot(covid_ave_df, aes(x = date, y = cases, color = ave_case_rate)) +
geom_point(size = 1) +
scale_y_continuous(labels = scales::comma) +
scale_color_manual(values = c("above" = "purple", "below" = "pink")) +
labs(title = "COVID 19 Confirmed Cases Status Over Time",
x = "Date",
y = "Cases",
color = "Cases Status")

## deaths status flow overtime
ggplot(covid_ave_df, aes(x = date, y = deaths, color = ave_death_rate)) +
geom_point(size = 1) +
scale_y_continuous(labels = scales::comma) +
scale_color_manual(values = c("above" = "blue", "below" = "lightgreen")) +
labs(title = "COVID 19 Confirmed Cases Status Over Time",
x = "Year",
y = "Deaths",
color = "Death Rate")
