Graph A shows the mean cumulative deaths over the weeks for countries split into 4 general life expectancy groups. Graph B shows the average deaths in each life expectancy group on April 12, 2021.
Both graphs show a higher correlation between death from Covid-19 and higher life expectancy.
# PLOT 1:
plot1<- ggplot(average_over_time, aes(x = Date, y = quart_avg)) +
labs(y="Deaths (per 100k)") +
geom_col(aes(fill = average_over_time$quart_avg)) +
ggtitle("Mean Cummulative Deaths vs Life Expectancy by Quartiles") +
theme(strip.text = element_text( size = 10, color = "white", hjust = 0.5 ),
strip.background = element_rect( fill = "#858585", color = NA ),
panel.background = element_rect( fill = "#efefef", color = NA ),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_line( color = "white" ),
panel.spacing.x = unit( 0.5, "cm" ),
panel.spacing.y = unit( 0.5, "cm" ),
legend.position = "none",
axis.text.x=element_text(angle=30, hjust=1),
axis.title.x = element_blank()) +
facet_wrap(~Quartile, labeller = as_labeller(label_names), ncol=2)
covid_most_recent <- covid_summary_ratios %>%
filter(Date == "2021-04-12")
m3 <- round(aggregate(covid_most_recent$deaths_per_100k, by=list(LE_group=covid_most_recent$Quartile), FUN = mean),0)
m3 <- as.data.frame(m3)
names(m3) <- c("LE_group", "avg_deaths_100k")
#PLOT 2:
gg <- ggplot(m3, aes(x = factor(LE_group), y = avg_deaths_100k)) +
geom_col(fill="lightblue") +
geom_text(aes(label = avg_deaths_100k), vjust = -0.5) +
labs(title= "Average Cummulative Deaths per 100K by Life Expectancy Quartiles",
x="Life Expectancy Groups", y="Cumulative Deaths (per 100k)") +
theme(legend.position = "none") +
scale_x_discrete(labels=c("1" = "Lowest", "2" = "Lower",
"3" = "Higher", "4" = "Highest")) +
theme_classic()
cowplot::plot_grid(plot1, gg , labels = "AUTO")
ggplot(covid_summary_ratios, aes(x=reorder(Country,LE_z), y=LE_z, fill = factor(Quartile), label=LE_z)) +
geom_bar(stat='identity') +
stat_summary(mapping = aes(x = reorder(Country, LE_z), y = deaths_per_100k, alpha = "Deaths Per 100k"),
fun = max, geom = "col", inherit.aes = FALSE) +
scale_alpha_manual(name = "Covid Deaths", values= c(.5,.5)) +
scale_fill_brewer(type = "div", palette = "Pastel2", labels = label_names) +
labs(title= "Have countries with higher life expectancy fared better with Covid-19 deaths around the world?",
y = "Normalized life expectancy and Cumulative Deaths per 100K Population",
x = "Country",
fill = "Life Expectancy Quartiles") +
theme_classic() +
guides(fill = guide_legend(reverse=TRUE))+
theme(text = element_text(size=8),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.line.x = element_blank()) +
theme(plot.title = element_text(hjust = .5, size = 12)) +
coord_flip()
# Country Date Deaths Cases Code
# "character" "Date" "numeric" "numeric" "character"
# x0_39yrs x40_65yrs OVER65yrs LE Quartile
# "numeric" "numeric" "numeric" "numeric" "integer"
# med_age LE_z LE_type young_to_old total_pop
# "character" "numeric" "character" "numeric" "numeric"
# deaths_per_100k cases_per_100k
# "numeric" "numeric"
# Animated plot
animation <- ggplot(
covid_summary_ratios,
aes(y = deaths_per_100k,
x = round(med_age,2),
size = total_pop,
colour = factor(Quartile))) +
geom_text(aes(label = Code), hjust= -.4, vjust=.5, angle =90)+
geom_point(alpha = 0.7, show.legend = TRUE) +
scale_colour_manual(values = c("#8DD3C7", "#FDCDAC", "#BEBADA", "#FA9FB5"),
name = "Life Expectancy Group",
labels = label_names) +
scale_size(range = c(2, 12)) +
theme(plot.caption = element_text(size = 18),
text = element_text(size = 20)) +
#gg animate specific details
labs(title = "Week: {frame_time}",
x = "Median Age",
y = "Deaths per 100K",
caption = "Bubble size is proportional to population\nBubble colors indicate life expectancy quartile group") +
guides(size = FALSE) +
transition_time(Date) +
ease_aes("linear") +
theme_classic()
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
animate(animation, nframes = 100, fps = 10, width = 1300, height = 800, end_pause = 30)