[This article was first published on R & Decision Making, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
< face="arial">To be honest, the main reason for me to send my kids back to school is to keep the household sane. Nevertheless, the decision should be informed by data.< >Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
< face="arial">
< >
< >
< face="arial">So here we go. I have downloaded the data from the UK government website and filtered the data by region. The UK lock down started 15th March when there were about 6 new cases per day. In the area I am at, the number of daily confirmed cases has come down below 6 per day for some time.< >
< face="arial">
< >
< >
< face="arial">I shall caveat that conservatively, we should check all the surrounding areas and wait for 0 cases for at least 2 weeks for all of them to be safe.< >
< face="arial">
< >
< >
< face="arial">I have schedule a job to update the graph every day to keep an eye on the number. For now and for my family, the risk is definitely worth taking.< >
< face="arial">#data.table #R #backtoschool #covid19 #parenthood< >
< face="trebuchet">
< >
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
< >
library(data.table) library(ggplot2) data_url <- "https://c19downloads.azureedge.net/downloads/csv/coronavirus-cases_latest.csv" raw_data <- fread(data_url, check.names = TRUE) merton_data <- raw_data[ Area.name == "Merton" & Area.type == "Upper tier local authority",, ][,Specimen.date := as.Date(Specimen.date) ][,c("Specimen.date","Daily.lab.confirmed.cases")][ order(Specimen.date) ] merton_data <- merge(merton_data, data.table(Specimen.date = seq( min(merton_data[,Specimen.date]), max(merton_data[,Specimen.date]), by = "1 day" )), all = TRUE, by = "Specimen.date") setkey(merton_data, Specimen.date) setnafill(merton_data, type = "const", fill = 0, cols = c("Daily.lab.confirmed.cases")) merton_data[,roll_mean := frollmean(Daily.lab.confirmed.cases, n = 7, align = "right")] m_merton_data <- melt(merton_data, id.vars="Specimen.date", measure.vars = c("Daily.lab.confirmed.cases","roll_mean")) merton_plot <- ggplot(m_merton_data, aes(x = Specimen.date, y = value, fill = variable, color = variable))+ geom_bar(data = subset(m_merton_data, variable == "Daily.lab.confirmed.cases"), stat = "identity") + geom_line(data = subset(m_merton_data, variable == "roll_mean")) + labs(x="Specimen Date", y="Number of Confirmed Cases", fill = "", color = "") + scale_fill_manual(values = c("#ff0000","#000000"), labels = c("Merton # Daily Confirmed cases", "7 day average")) + scale_color_manual(values = c("#ff0000","#000000"), labels = c("Merton # Daily Confirmed cases", "7 day average")) + scale_x_date(date_breaks = "2 weeks", date_labels = "%Y-%m-%d") + theme_bw() %+replace% theme(legend.position = "top", legend.justification = "left") ggsave(filename = "Merton_COVID.png", merton_plot, width = 10, height = 6)
To leave a comment for the author, please follow the link and comment on their blog: R & Decision Making.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.