Last active
December 19, 2025 01:51
-
-
Save abikoushi/97d1ccbe89ad2d1f076db2177f88bb7b to your computer and use it in GitHub Desktop.
get MERS-2025 data using rvest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(dplyr) | |
| library(tidyr) | |
| library(rvest) | |
| library(readr) | |
| url = "https://ja.wikipedia.org/wiki/2015年韓国におけるMERSの流行" | |
| taball <- read_html(url) |> | |
| html_table() | |
| dat <- rename( | |
| taball[[2]], | |
| Date = 日付, | |
| Cases = `感染者数[35]`, | |
| Deaths = `死亡者数[35]` | |
| ) %>% | |
| dplyr::filter(!grepl("総", Date)) %>% | |
| mutate(Date = gsub("2015年", "", Date)) %>% | |
| mutate(Date = gsub("日", "", Date)) %>% | |
| mutate(Date = gsub("年|月", "-", Date)) %>% | |
| mutate(Date = as.Date(paste("2015", Date, sep = "-"))) %>% | |
| mutate( | |
| Cases = gsub("人", "", Cases), | |
| Deaths = gsub("人", "", Deaths) | |
| ) %>% | |
| mutate( | |
| Cases = gsub("\\[.+\\]", "", Cases), | |
| Deaths = gsub("\\[.+\\]", "", Deaths) | |
| ) %>% | |
| mutate( | |
| Cases = as.integer(Cases), | |
| Deaths = if_else(Deaths == "", 0L, as.integer(Deaths)) | |
| ) | |
| write_csv(dat, file = "MERS2015.csv") | |
| datl = pivot_longer(dat, Cases:Deaths, names_to = "variable") | |
| ggplot(datl, aes(x = Date, y = value, colour = variable, linetype = variable)) + | |
| geom_line() + | |
| theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment