Skip to content

Instantly share code, notes, and snippets.

@felixgolcher
Last active March 26, 2020 08:48
Show Gist options
  • Save felixgolcher/114249241a0b77ab1b56162f84f7c6be to your computer and use it in GitHub Desktop.
Save felixgolcher/114249241a0b77ab1b56162f84f7c6be to your computer and use it in GitHub Desktop.
[absolutely obsolete] Code and data for simple plots about the corona virus outbreak at the beginning of 2020
date suspected confirmed deaths
2020-01-10 NA 41 1
2020-01-11 NA 41 1
2020-01-12 NA 41 1
2020-01-13 NA 41 1
2020-01-15 NA NA 2
2020-01-16 NA 45 NA
2020-01-17 NA 62 2
2020-01-18 NA 121 NA
2020-01-19 NA 198 3
2020-01-20 54 291 6
2020-01-21 37 440 9
2020-01-22 257 571 17
2020-01-23 1072 830 25
2020-01-24 1965 1287 41
2020-01-25 2684 1975 56
2020-01-26 5794 2744 80
2020-01-27 6973 4515 106
2020-01-28 9239 5974 132
2020-01-29 12167 7711 170
2020-01-30 15238 9692 213
2020-01-31 17988 11791 259
2020-02-01 19544 14380 304
2020-02-02 21558 17205 361
2020-02-03 23214 20440 425
2020-02-04 23260 24324 490
2020-02-05 24702 28018 563
2020-02-06 26359 31161 637
2020-02-07 27657 34568 722
2020-02-08 28942 37198 811
library(tidyverse)
library(ggplot2)
# using csv now
# library(readODS)
# height of figs
mh <- 3
# width
mw <- mh*1.5
# data (manually) gathered from
# https://en.wikipedia.org/wiki/Timeline_of_the_2019%E2%80%9320_Wuhan_coronavirus_outbreak
### converting the orig ods file.
# cwp <- read_ods("corona_wp.ods")
# write_csv(cwp, "corona_wp.csv")
cwp <- read_csv("corona_wp.csv")
# even linear display of confirmed shows a downard curvature.
(ggplot(cwp, aes(date, confirmed))+
geom_point()+
ggtitle("Confirmed cases in linear scale")+
theme_minimal()->gg1)
ggsave("confirmed_lin.png", width=mw, height = mh)
# not an exponential development for quite a while:
(gg1 + scale_y_log10("confirmed (log scale)")+
ggtitle("Confirmed cases in log scale") -> gg1a)
ggsave("confirmed_log.png", width=mw, height = mh)
# deaths more regular, more exp.:
(ggplot(cwp, aes(date, deaths))+
geom_point()+
ggtitle("Deaths in linear scale")+
theme_minimal()-> gg2)
ggsave("deaths_lin.png", width=mw, height = mh)
# but not really exponential either, even if you can decide to call stretches of
# it exponential.
gg2 + scale_y_log10("deaths (log scale)")+
ggtitle("Deaths in log scale")
ggsave("deaths_log.png", width=mw, height = mh)
(cwp %>%
pivot_longer(-date, names_to = "description", values_to = "count")->cwp.long) %>%
filter(description != "suspected") %>%
## suspected cases are current, not cumulative.
ggplot(aes(date, count, col=description))+
geom_point()+
scale_y_log10()+
theme_minimal()
ggsave("both_log.png", width=mw, height = mh)
## there was a strange blip in suspected cases on feb 03/04.
ggplot(cwp, aes(date, suspected))+
geom_point()
## deaths by confirmed went down for a long while, and then up again, but that
## is to be expected as the number of confirmed cases grows slower.
ggplot(cwp, aes(date, deaths/confirmed, size=confirmed))+
geom_point(alpha=.7)
ggsave("frac.png", width=mw, height = mh)
## the relative daily increase goes consistently down.
cwp %>% mutate(inc.perc = confirmed/lag(confirmed)-1) %>%
ggplot(aes(date, inc.perc, size=confirmed))+
geom_point(alpha=.7)+
ggtitle("daily relative increase in confirmed cases")+
scale_y_continuous("increase in percent")
ggsave("inc.png", width=mw, height = mh)
# the _absolute_ daily increase shows a somewhat strange behaviour. It could be
# explained by a genuine success of the chinese efforts to combat the virus or
# on limited testing capacities. The latter explanation cannot easily cope with
# the general downward trend over the last few days.
cwp %>% mutate(inc.abs = confirmed-lag(confirmed)) %>%
ggplot(aes(date, inc.abs, size=confirmed))+
geom_point(alpha=.7)+
ggtitle("daily absolute increase in confirmed cases")+
scale_y_continuous("absolute increase")
ggsave("incabs.png", width=mw, height = mh)
## the daily increase in deaths does not follow the pattern of confirmed cases
## (yet?), but that is not to be expected either.
cwp %>% mutate(inc.abs = deaths-lag(deaths)) %>%
ggplot(aes(date, inc.abs, size=confirmed))+
ggtitle("daily absolute increase in deaths")+
geom_point(alpha=.7)+
scale_y_continuous("absolute increase (deaths)")
ggsave("incabs-death.png", width=mw, height = mh)
@felixgolcher
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment