Skip to content

Instantly share code, notes, and snippets.

@cgpu
Last active March 18, 2020 10:52
Show Gist options
  • Save cgpu/4dca0f3d823489aa0a7fca6c11f9bd63 to your computer and use it in GitHub Desktop.
Save cgpu/4dca0f3d823489aa0a7fca6c11f9bd63 to your computer and use it in GitHub Desktop.
Grouped barplot for the countries were testing and confirmed cases are available.
# covid19 <- data.table::fread("https://covid.ourworldindata.org/data/full_data.csv")
# source: https://ourworldindata.org/coronavirus-source-data
# covid_test_coverage <- data.table::fread("covid-19-tests-country.csv")
# source: https://ourworldindata.org/coronavirus#current-covid-19-test-coverage-estimates
# total_confirmed_cases <- data.table::fread("total_cases.csv")
library(ggplot)
library(plotly)
# dput dump for getting the dataframe fast
toPlot <- structure(list(countries = structure(c(26L, 13L, 26L, 13L, 22L,
28L, 8L, 14L, 14L, 3L, 19L, 8L, 2L, 28L, 17L, 17L, 27L, 19L,
29L, 6L, 11L, 16L, 6L, 2L, 24L, 16L, 5L, 21L, 27L, 3L, 12L, 5L,
7L, 7L, 29L, 9L, 10L, 23L, 11L, 10L, 20L, 24L, 25L, 12L, 20L,
21L, 15L, 4L, 18L, 22L, 4L, 1L, 23L, 9L, 25L, 18L, 1L, 15L), .Label = c("Armenia",
"Austria", "Bahrain", "Croatia", "Czech Republic", "Denmark",
"Finland", "France", "Hungary", "Iceland", "India", "Ireland",
"Italy", "Japan", "Lithuania", "Malaysia", "Netherlands", "New Zealand",
"Norway", "Philippines", "Poland", "Russia", "Slovakia", "Slovenia",
"South Africa", "South Korea", "Thailand", "United Kingdom",
"Vietnam"), class = "factor"), metric = c("test", "confirmed",
"confirmed", "test", "test", "test", "confirmed", "test", "confirmed",
"test", "test", "test", "test", "confirmed", "test", "confirmed",
"test", "confirmed", "test", "confirmed", "test", "test", "test",
"confirmed", "test", "confirmed", "test", "test", "confirmed",
"confirmed", "test", "confirmed", "confirmed", "test", "confirmed",
"test", "test", "test", "confirmed", "confirmed", "test", "confirmed",
"test", "confirmed", "confirmed", "confirmed", "test", "test",
"test", "confirmed", "confirmed", "test", "confirmed", "confirmed",
"confirmed", "confirmed", "confirmed", "confirmed"), count = c(248647,
145413, 119049, 86011, 76963, 29764, 25931, 10205, 9941, 9201,
8000, 6628, 6582, 6325, 6000, 5488, 5232, 4854, 4588, 4309, 4058,
4010, 3839, 3680, 3058, 2549, 2353, 2234, 1941, 1850, 1784, 1069,
958, 900, 890, 858, 856, 853, 824, 799, 717, 713, 645, 638, 626,
481, 366, 344, 338, 295, 269, 211, 189, 166, 157, 67, 54, 48)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -58L))
gg <- ggplot(toPlot, aes(fill=metric,
y=count,
x=countries)) +
geom_bar(position="dodge", stat="identity") +
theme(text = element_text( color = "#4A637B", face = "bold", family = 'Helvetica')
,plot.caption = element_text(size = 9, color = "#8d99ae", face = "plain" )
,plot.title = element_text(size = 18, color = "#2b2d42", face = "bold", hjust=0.15 )
,axis.text.y = element_text(size = 10, color = "#8d99ae", face = "bold", hjust=1.1 )
,axis.title.x = element_text(size = 14 , hjust = 0.15 )
,axis.text.x = element_blank()
,axis.title.y = element_blank()
,axis.ticks.x = element_blank()
,axis.ticks.y = element_blank()
,plot.margin = unit(c(1,1,1,1),"cm")
,panel.background = element_blank()
,legend.position = "none"
,aspect.ratio = 0.75) +
theme_light() +
scale_fill_manual(values = c("#f35f71", "#4974a5")) + coord_flip()
plotly::ggplotly(gg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment