This report is an analysis on the COVID-19 New York Time dataset.It uses five charts to show where cases and deaths were concentrated and how they changed over time
The report looks at the data from five angles:
The file contains the COVID-19 cases and deaths for each US state recorded by the date
library(ggplot2)
library(dplyr)
library(data.table)
library(lubridate)
library(scales)
library(plotly)
filename ="us-states.csv"
df= fread(filename,na.strings=c(NA,""))
df$date = ymd(df$date)
df$year = year(df$date)
#final totals per state
df_last = df[df$date == max(df$date), ]
#Daily new cases and new deaths
df = df %>%
arrange(state, date) %>%
group_by(state) %>%
mutate(new_cases = pmax(cases - lag(cases, default = 0), 0),
new_deaths = pmax(deaths - lag(deaths, default = 0), 0)) %>%
ungroup()
The data covers 56 states and territories, from 2020-01-21 to 2023-03-23
Below are the five charts.
This chart shows the ten states with the most total COVID-19 cases as of the latest date in the dataset. It helps compare which states had the highest case count
topten = df_last[order(df_last$cases, decreasing = TRUE), ]
topten = topten[1:10, ]
ggplot(topten, aes(x = reorder(state, cases), y = cases)) +
geom_bar(stat = "identity", fill = "darkorange", width = 0.7) +
labs(title = "Top 10 States by COVID Cases", x = "State", y = "Number of Cases") +
scale_y_continuous(labels = comma) +
coord_flip() +
theme_minimal()
As of 2023-03-23, California had the most total COVID-19 cases, with about 12,169,158, followed by Texas (8,447,168) and Florida (7,542,869). Together, the top 10 states account for 54% of all cases in the dataset.
This shows how the tatal deaths are spread across all the states.The bars group states into a range of death counts.The number that is on top is the nukmber of states that fall in the range. With this we can see that most of the states fall in the lower end with only a few states having very high totals
ggplot(df_last, aes(x = deaths)) +
geom_histogram(bins = 8, color = "red", fill = "darkorange") +
stat_bin(bins = 8, geom = "text", color = "black",
aes(label = after_stat(count)), vjust = -0.5) +
labs(title = "COVID Deaths by State", x = "Deaths", y = "No. of States") +
scale_x_continuous(labels = comma) +
scale_y_continuous(labels = comma)
Across the 56 states and territories in the data, most states recorded about 13,250 deaths. The state with the most deaths was California, with 104,277, while the lowest total was 34 in American Samoa.
This shows the new cases added up acrooss each state for each month.This graph shows how the pandemic changed over time with the peaks being waves of infection and the dips being when the infection quieted down.
months_df = df %>%
mutate(month = floor_date(date, "month")) %>%
group_by(month) %>%
summarise(n = sum(new_cases), .groups = 'keep') %>%
data.frame()
x_axis_labels = seq(min(months_df$month), max(months_df$month), by = "3 months")
ggplot(months_df, aes(x = month, y = n)) +
geom_line(color = 'darkorange', linewidth = 1) +
geom_point(shape = 21, size = 4, color = 'red', fill = 'white') +
labs(x = "Month", y = "New Cases", title = "US New COVID Cases by Month")+
scale_y_continuous(labels = comma) +
theme_light() +
theme(plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_x_date(labels = label_date("%b %Y"), breaks = x_axis_labels,
minor_breaks = NULL)
the monthly new cases were highest in January 2022, and about 20,304,991 new cases were recorded across all states.the data records 104,063,072 new cases between January 2020 and March 2023.
This shows the percentage of each states total cases that happened in that year for the top 10 states.The darker red meas a larger share of that staes cases happened in that year
top10_states = df_last[order(df_last$cases, decreasing = TRUE), ]$state[1:10]
year_state_df = df %>%
filter(state %in% top10_states) %>%
group_by(state, year) %>%
summarise(n = sum(new_cases), .groups = "drop") %>%
group_by(state) %>%
mutate(pct = n / sum(n)) %>%
ungroup() %>%
mutate(state = factor(state, levels = top10_states),
year = factor(year)) %>%
data.frame()
ggplot(year_state_df, aes(x = year, y = state, fill = pct)) +
geom_tile(color = "black") +
geom_text(aes(label = percent(pct, accuracy = 1))) +
coord_equal(ratio = 1) +
labs(title = "Share of each state's cases by year",
x = "Year",
y = "State",
fill = "Shares of state's") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5)) +
scale_y_discrete(limits = rev(levels(year_state_df$state))) +
scale_fill_continuous(low = "white", high = "red",
labels = percent)
This chart splits the total US COVID-19 deaths by year.Each slice of the chart represents one year and the center shows the total deaths overall.You can hover over the slices to see the exact deaths and percentages
year_df = df %>%
group_by(year) %>%
summarise(n = sum(new_deaths), .groups = "drop") %>%
mutate(year = as.character(year)) %>%
data.frame()
plot_ly(year_df, labels = ~year, values = ~n) %>%
add_pie(hole = 0.6) %>%
layout(title = "US COVID-19 deaths per year ") %>%
layout(annotations = list(text = paste0("Total Deaths: \n",
scales::comma(sum(year_df$n))),
"showarrow" = F))
Across the whole dataset, there were 1,143,615 recorded COVID-19 deaths. 2021 accounts for the largest share, with 480,982 deaths (42% . The smallest share is 2023, with 35,707 deaths (3%)
All together this data set shows where the COVID cases and deaths were concentrarted how the cases changed over time and how the burden was split across the years The main findings were: