Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
Last active January 11, 2022 00:29
Show Gist options
  • Save thoughtfulbloke/23b1d958b5875ff32ba17489807970dc to your computer and use it in GitHub Desktop.
Save thoughtfulbloke/23b1d958b5875ff32ba17489807970dc to your computer and use it in GitHub Desktop.
graph of positive covid cases in MiQ
library(rvest)
library(dplyr)
library(lubridate)
library(readr)
library(ggplot2)
library(ggthemes)
library(ggridges)
source("davidise.R")
# saving reports from the website as html into a folder
# called news_item_html
MiQnews <- list.files("../news_item_html", pattern=".*html$")
extract_numbers <- function(x) {
file_w._path <- paste0("../news_item_html/",x)
report_date <- ymd(x)
tbls <- file_w._path %>%
read_html() %>%
html_nodes("table") %>%
html_table(header=TRUE)
newMiQ <- as.data.frame(tbls[[1]])
arrived <- dmy(paste(newMiQ$`Arrival date`, "2022"))
arrived[month(arrived) > 10] <- arrived[month(arrived) > 10] - years(1)
report <- data.frame(arrived)
report$reported <- report_date
return(report)
}
list_of_reports <- lapply(MiQnews, extract_numbers)
df_reports <- bind_rows(list_of_reports)
reportgrf <- ggplot(df_reports, aes(x=arrived, y=reported, group=reported)) +
geom_density_ridges(stat = "binline", binwidth = 1, scale = 0.95) +
labs(title="Count of MiQ arrival dates of postive cases",
y="(1pm) Report Date", x="Date arrived in MiQ",
caption="Source: MoH 1pm briefings")
davidise_graph(reportgrf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment