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

library(tidyverse) 
library(rvest)
library(lubridate)
url <- "https://www.mhlw.go.jp/stf/newpage_09849.html"
h <- read_html(url)
tab <- h %>% html_nodes("table")
tab <- tab[[3]] %>% html_table 
# str(tab)
dat <- tab
colnames <- dat[1,]
colnames(dat) <- colnames
dat <- dat[2:181,]
dat <- dat[,3:5]
dat
dat0 <- dat %>% group_by(性別) %>% summarize(計 = n()) %>% mutate(割合 = 計/sum(計))
dat0 %>% ggplot(aes(性別, 計)) + geom_col(aes(fill = 性別)) +
  theme_gray(base_family = "HiraKakuPro-W3") + 
  scale_fill_manual(values=c("#00FF00", "#FF0000", "#0000FF"))

dat1 <- dat %>% group_by(年代, 性別) %>% summarize(計 = n())
dat1 %>% ggplot(aes(x = 年代, y = 計, fill = 性別)) + geom_bar(stat = "identity") + 
  theme_gray(base_family = "HiraKakuPro-W3") +
  scale_fill_manual(values=c("#00FF00", "#FF0000", "#0000FF"))

dat2 <- dat %>% group_by(確定日, 性別) %>% summarize(計 = n()) 
dat2$確定日1 <- as.Date(dat2$確定日, "%m/%d")
dat2$確定日1 <- paste0(as.character(month(dat2$確定日1)),"/",substr(as.character(dat2$確定日1), 9,10))
dat2$確定日1[dat2$確定日1=="NA/NA"] <- "調査中"
# dat2$確定日1
dat2 %>% ggplot(aes(x = 確定日1, y = 計, fill = 性別)) + geom_bar(stat = "identity") +  
  theme_gray(base_family = "HiraKakuPro-W3") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  scale_fill_manual(values=c("#00FF00", "#FF0000", "#0000FF")) +
  xlab("確定日")

参考