日本における、コロナウイルス感染者確認数(日毎)

library(tidyverse) 
library(rvest)
library(lubridate)
url <- "https://www.mhlw.go.jp/stf/newpage_09849.html"
h <- read_html(url)
# html_text(h)
# read the third table
tab <- h %>% html_nodes("table")
tab <- tab[[3]] %>% html_table 
# str(tab)
dat <- tab
colnames(dat) <- dat[1,]
dat <- dat[2:181,]
dat <- dat %>% mutate(date = mdy(paste(dat[,3],"/2020")))
dat <- dat %>% mutate(sex = ifelse(dat[,5]=='女', 'F','M'))
dat <- dat %>% mutate(age = as.numeric(substr(dat[,4],1,2)))
dat$age[dat[,4]=='10歳未満']<-0
# delete the data when is.na(dat$date) is true
dat <- dat[!is.na(dat$date),]
dat3 <- dat %>% select(date, sex, age) %>% arrange(date)
s <- dat3 %>% group_by(date) %>% summarize(count_by_date = n()) 
s %>% ggplot()  + geom_col(aes(x=date, y=count_by_date)) 

dat3 %>%  ggplot(aes(date)) + geom_density(fill="grey50")

# s

参考