GithubHelp home page GithubHelp logo

dataallaround / mapcovid19 Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 2.98 GB

COVID-19 Datasets with Coordinates

License: MIT License

R 100.00%
covid-19 maps covid19-map mapping shapefile geojson ncov-2019 ncov-data-visual ncov-map

mapcovid19's Introduction

COVID-19 Datasets with Coordinates

DOI CodeFactor

This repository aims to simplify the visualisation of the COVID-19 datasets. Data and geometries are provided in the same file and with different formats to immediately plot the data in R or other software for geospatial data.

The R folder provides functions to directly download the data in R, for Italy, and USA.

For more details on the functions and packages used look at the references section.

Table of contents

Download in R

functions description
getDataCovid_IT() retrives data from this repository for the italian cases
getDataCovid_US() retrives data from this repository for the United States of America cases

Italy

Data can be downloaded first loaded the R function getDataCovid_IT() available in the R folder of this repo:

library(devtools)
source_url("https://raw.githubusercontent.com/dataallaround/mapCOVID19/master/R/getDataCovid_IT.R")

getDataCovid_IT() requires the date in the format yyyy-mm-dd, and the geographical level, "regioni" or "province":

dt = getDataCovid_IT(date = "2020-04-17", level = "regioni")
names(dt)
##  [1] "date"                       "ripartizione"               "regione"                   
##  [4] "hospitalized"               "ventilation"                "hospitalized_total"        
##  [7] "confinement"                "current_positive"           "variation_current_positive"
## [10] "new_positive_total"         "recovered"                  "death"                     
## [13] "positive"                   "tests"                      "geometry"

for "regions", and for "province":

dt = getDataCovid_IT(date = "2020-04-17", level = "province")
names(dt)
## [1] "regione"      "provincia"    "date"         "ripartizione" "positive"     "geometry"

Multiple date can be loaded and aggregate in a single file:

dt = getDataCovid_IT(date = c("2020-04-17","2020-04-16"), level = "regioni")
names(dt)
##  [1] "date"                       "ripartizione"               "regione"                   
##  [4] "hospitalized"               "ventilation"                "hospitalized_total"        
##  [7] "confinement"                "current_positive"           "variation_current_positive"
## [10] "new_positive_total"         "recovered"                  "death"                     
## [13] "positive"                   "tests"                      "geometry"

Data can be also downloaded using "download_dir" in getDataCovid_IT() function, indicating the destination directory.

USA

Data can be downloaded first loaded the R function getDataCovid_US() available in the R folder of this repo:

library(devtools)
source_url("https://raw.githubusercontent.com/dataallaround/mapCOVID19/master/R/getDataCovid_US.R")

getDataCovid_US() requires the date in the format yyyy-mm-dd, for only the states of US:

dtUS = getDataCovid_US(date = "2020-04-17")
names(dtUS)
##  [1] "abbr"                 "state"                "date"                 "Confirmed"           
##  [5] "Deaths"               "Recovered"            "Active"               "FIPS"                
##  [9] "Incident_Rate"        "People_Tested"        "People_Hospitalized"  "Mortality_Rate"      
## [13] "UID"                  "ISO3"                 "Testing_Rate"         "Hospitalization_Rate"
## [17] "geometry"

Multiple date can be loaded and aggregate in a single file:

dtUS = getDataCovid_US(date = c("2020-04-17","2020-04-16"))
names(dtUS)
##  [1] "abbr"                 "state"                "date"                 "Confirmed"           
##  [5] "Deaths"               "Recovered"            "Active"               "FIPS"                
##  [9] "Incident_Rate"        "People_Tested"        "People_Hospitalized"  "Mortality_Rate"      
## [13] "UID"                  "ISO3"                 "Testing_Rate"         "Hospitalization_Rate"
## [17] "geometry"

Data can be also downloaded using "download_dir" in getDataCovid_US() function, indicating the destination directory.

WORLD

Data can be downloaded first loaded the R function getDataCovid_WORLD() available in the R folder of this repo:

library(devtools)
source_url("https://raw.githubusercontent.com/dataallaround/mapCOVID19/master/R/getDataCovid_WORLD.R")

getDataCovid_WORLD() requires the date in the format yyyy-mm-dd, for only the states of US:

dtWD = getDataCovid_WORLD(date = "2020-04-17")
names(dtWD)
##  [1] "date"                 "country"              "country_id"           "iso3"                
##  [5] "region"               "deaths"               "cumulative_deaths"    "confirmed"           
##  [9] "cumulative_confirmed" "geometry"

Multiple date can be loaded and aggregate in a single file:

dtWD = getDataCovid_WORLD(date = c("2020-04-17","2020-04-16"))
names(dtWD)
##  [1] "date"                 "country"              "country_id"           "iso3"                
##  [5] "region"               "deaths"               "cumulative_deaths"    "confirmed"           
##  [9] "cumulative_confirmed" "geometry"

Specific countries can be download used country for the country name, country_id for iso2 country id, and country_iso3 for iso3 country id.

dtWD = getDataCovid_WORLD(date = "2020-04-19", country =  "Italy")
names(dtWD)
##  [1] "date"                 "country"              "country_id"           "iso3"                
##  [5] "region"               "deaths"               "cumulative_deaths"    "confirmed"           
##  [9] "cumulative_confirmed" "geometry"
  dtWD = getDataCovid_WORLD(date = c("2020-04-18","2020-04-19"), country_iso3 =  c("ITA", "ESP"))
  names(dtWD)
##  [1] "date"                 "country"              "country_id"           "iso3"                
##  [5] "region"               "deaths"               "cumulative_deaths"    "confirmed"           
##  [9] "cumulative_confirmed" "geometry"

Data can be also downloaded using "download_dir" in getDataCovid_US() function, indicating the destination directory.

Static map examples in R

Some examples to map the data in R software.

library(sf)
library(tmap)
library(cartography)
suppressMessages(tmap_mode("plot"))

dt = getDataCovid_IT(date = "2020-04-17", level = "regioni")
dtUS = getDataCovid_US(date = "2020-04-17")
dtWD = getDataCovid_WORLD(date = "2020-04-19")
tm_shape(dt) + tm_borders() + tm_fill("positive") + tm_layout(frame = FALSE)

library("grid")
alaska <- tm_shape(dtUS[dtUS$state=="Alaska",], projection = 3338) + tm_borders() + tm_layout("Alaska", legend.show = FALSE, bg.color = NA, title.size = 0.8, frame = FALSE) + tm_fill("Confirmed", n = 10) 

hawaii <- tm_shape(dtUS[dtUS$state=="Hawaii",], projection = 3759) + tm_borders() +    tm_layout("Hawaii",legend.show = FALSE, bg.color=NA, title.position = c("LEFT", "BOTTOM"), title.size = 0.8, frame=FALSE) + tm_fill("Confirmed", n = 10) 

alk <- viewport(x = 0.15, y = 0.15, width = 0.3, height = 0.3)
haw <- viewport(x = 0.4, y = 0.1, width = 0.2, height = 0.1)

tm_shape(dtUS[!(dtUS$state %in% c("Alaska", "Hawaii")),],  projection=2163) + tm_borders() + tm_fill("Confirmed", n = 10) +  tm_layout(legend.position = NULL, frame = FALSE, inner.margins = c(0.1, 0.1, 0.05, 0.05), legend.show = FALSE)
print(alaska, vp = alk)
print(hawaii, vp = haw)

tm_shape(dtWD) + tm_borders() + tm_fill("deaths", n = 10) + tm_layout(frame = FALSE, legend.show = TRUE)

tm_shape(dt) + tm_borders() + tm_fill("positive", n = 10) + tm_facets("regione")

For different date we can plot as follows:

dt = getDataCovid_IT(date = c("2020-04-17","2020-04-16","2020-04-15"), level = "regioni")
tm_shape(dt) + tm_borders() + tm_fill("positive") + tm_facets("date")

dtWD = getDataCovid_WORLD(date = c("2020-04-01","2020-04-19"), country_iso3 =  c("ITA", "ESP"))
tm_shape(dtWD) + tm_borders() + tm_fill("deaths") + tm_facets(c("date","country"))

Starting from nuts3 (regions), we can aggregate, for example, by nuts1 (ripartizione)

dt = getDataCovid_IT(date = c("2020-04-17"), level = "province")
dt_aggr <- aggregate(dt[,"positive"], by = list( group = dt[,"ripartizione", drop = TRUE]), FUN = sum)
tm_shape(dt_aggr) + tm_borders() + tm_fill("positive")

tm_shape(dt_aggr) + tm_borders() + tm_fill("positive") + tm_facets("group")

Dynamic map examples in R

library(tmap)
library(mapview)
suppressMessages(tmap_mode("view"))

dt = getDataCovid_IT(date = "2020-04-17", level = "regioni")
dtUS = getDataCovid_US(date = "2020-04-17")
tm_shape(dt) + tm_borders() + tm_fill("positive")
tm_shape(dtUS) + tm_borders() + tm_fill("Confirmed")
mapview(dt, zcol = "positive")
mapview(dtUS, zcol = "Confirmed")

Sources

References

Citation

Serafini A. (2020). dataallaround/mapCOVID19: mapCOVID19 (Version v1.0) [Data set]. Zenodo. http://doi.org/10.5281/zenodo.3763033

@dataset{alessio_2020_3763033,
  author       = {Alessio},
  title        = {dataallaround/mapCOVID19: mapCOVID19},
  month        = apr,
  year         = 2020,
  publisher    = {Zenodo},
  version      = {v1.0},
  doi          = {10.5281/zenodo.3763033},
  url          = {https://doi.org/10.5281/zenodo.3763033}
}

mapcovid19's People

Contributors

serafinialessio avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.