Skip to content

Commit

Permalink
Update JPN
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele Guidotti committed Mar 9, 2023
1 parent c39e183 commit ec8865d
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 71 deletions.
83 changes: 83 additions & 0 deletions R/ds_github.lisphilar.covid19sir.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#' Hirokazu Takaya
#'
#' Data source for: Japan
#'
#' @param level 1, 2
#'
#' @section Level 1:
#' - confirmed cases
#' - deaths
#' - recovered
#' - tests
#' - total vaccine doses administered
#' - people with at least one vaccine dose
#' - people fully vaccinated
#' - hospitalizations
#' - intensive care
#'
#' @section Level 2:
#' - confirmed cases
#' - deaths
#' - recovered
#' - tests
#' - hospitalizations
#' - intensive care
#'
#' @source https://github.com/lisphilar/covid19-sir
#'
#' @keywords internal
#'
github.lisphilar.covid19sir <- function(level) {
if(!level %in% 1:2) return(NULL)

if(level==1){

url <- "https://raw.githubusercontent.com/lisphilar/covid19-sir/main/data/japan/covid_jpn_total.csv"
x <- read.csv(url, na.strings = c("0", "NA"))

x <- x[x$Location=="Domestic",]
x <- map_data(x, c(
"Date" = "date",
"Positive" = "confirmed",
"Tested" = "tests",
"Discharged" = "recovered",
"Hosp_require" = "hosp",
"Hosp_severe" = "icu",
"Fatal" = "deaths",
"Vaccinated_1st" = "people_vaccinated",
"Vaccinated_2nd" = "people_fully_vaccinated",
"Vaccinated_3rd" = "vaccines_3",
"Vaccinated_4th" = "vaccines_4",
"Vaccinated_5th" = "vaccines_5"
))

x$vaccines <- x$people_vaccinated +
tidyr::replace_na(x$people_fully_vaccinated, 0) +
tidyr::replace_na(x$vaccines_3, 0) +
tidyr::replace_na(x$vaccines_4, 0) +
tidyr::replace_na(x$vaccines_5, 0)

}

if(level==2){

url <- "https://raw.githubusercontent.com/lisphilar/covid19-sir/main/data/japan/covid_jpn_prefecture.csv"
x <- read.csv(url, na.strings = c("0", "NA"))

x <- map_data(x, c(
"Date" = "date",
"Prefecture" = "prefecture",
"Positive" = "confirmed",
"Tested" = "tests",
"Discharged" = "recovered",
"Hosp_require" = "hosp",
"Hosp_severe" = "icu",
"Fatal" = "deaths"
))

}

x$date <- as.Date(x$date)

return(x)
}
24 changes: 8 additions & 16 deletions R/iso_JPN.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@ JPN <- function(level){
#'
if(level==1){

#' - \href{`r repo("toyokeizai.net")`}{Toyo Keizai}:
#' - \href{`r repo("github.lisphilar.covid19sir")`}{Hirokazu Takaya}:
#' confirmed cases,
#' deaths,
#' recovered,
#' tests,
#' hospitalizations,
#' intensive care.
#'
x1 <- toyokeizai.net(level = level)

#' - \href{`r repo("ourworldindata.org")`}{Our World in Data}:
#' total vaccine doses administered,
#' people with at least one vaccine dose,
#' people fully vaccinated.
#' people fully vaccinated,
#' hospitalizations,
#' intensive care.
#'
x2 <- ourworldindata.org(id = "JPN") %>%
select(-c("tests", "hosp", "icu"))

# merge
x <- full_join(x1, x2, by = "date")
x <- github.lisphilar.covid19sir(level = level)

}

Expand All @@ -44,16 +36,16 @@ JPN <- function(level){
#'
if(level==2){

#' - \href{`r repo("toyokeizai.net")`}{Toyo Keizai}:
#' - \href{`r repo("github.lisphilar.covid19sir")`}{Hirokazu Takaya}:
#' confirmed cases,
#' deaths,
#' recovered,
#' tests,
#' hospitalizations,
#' intensive care.
#'
x <- toyokeizai.net(level = level)
x$id <- id(x$prefecture, iso = "JPN", ds = "toyokeizai.net", level = level)
x <- github.lisphilar.covid19sir(level = level)
x$id <- id(x$prefecture, iso = "JPN", ds = "github.lisphilar.covid19sir", level = level)

}

Expand Down
Loading

0 comments on commit ec8865d

Please sign in to comment.