Lecture: COVID-19のデータを集計, r ver. 2

I.データ

 

COVID-19の包括的な最新データを次で入手できます。RやPythonやJuliaなどによるロード方法も紹介されています。

 

COVID-19 Data Hub

 

次のように35の変数があります。

 

> colnames(x)
 [1] "id"                                  "date"                               
 [3] "tests"                               "confirmed"                          
 [5] "recovered"                           "deaths"                             
 [7] "hosp"                                "vent"                               
 [9] "icu"                                 "population"                         
[11] "school_closing"                      "workplace_closing"                  
[13] "cancel_events"                       "gatherings_restrictions"            
[15] "transport_closing"                   "stay_home_restrictions"             
[17] "internal_movement_restrictions"      "international_movement_restrictions"
[19] "information_campaigns"               "testing_policy"                     
[21] "contact_tracing"                     "stringency_index"                   
[23] "iso_alpha_3"                         "iso_alpha_2"                        
[25] "iso_numeric"                         "currency"                           
[27] "administrative_area_level"           "administrative_area_level_1"        
[29] "administrative_area_level_2"         "administrative_area_level_3"        
[31] "latitude"                            "longitude"                          
[33] "key"                                 "key_apple_mobility"                 
[35] "key_google_mobility"

 

II.Rによる集計

 

1.6月24日現在の国別感染者数の降のグラフ

 

 

2.6月24日現在の国別(+ダイヤモンド・プリンセス)人口比感染者数のグラフ

 

 

スクリプト

 

# install the package
install.packages("COVID19")
# load the package
library(COVID19)
library(tidyverse)

# Worldwide data by country
x <- covid19()
# column names
colnames(x)

## deaths in descending order
x_selected <- x %>% 
  select(id, administrative_area_level_1, date, confirmed, deaths, population) %>%
  filter(date == "2020-06-24") %>% 
  arrange(desc(deaths)) %>% 
  head(20)
# create a bar plot
p1 <- ggplot(x_selected, mapping = aes(x=reorder(administrative_area_level_1, deaths), deaths, fill = administrative_area_level_1)
p1 + geom_bar(stat="identity") +
  guides(fill=FALSE) +
  xlab("Country") +
  ylab("Deaths") +
  ggtitle("COVID-19 TOTAL DEATH") +
  coord_flip()

## deaths by population in descending order
x_selected_byPopulation <- x %>% 
  select(id, administrative_area_level_1, date, confirmed, deaths, population) %>%
  filter(date == "2020-06-24") %>%
  group_by(administrative_area_level_1) %>%
  summarize(deathsByPopulation = deaths/population) %>% 
  arrange(desc(deathsByPopulation)) %>% 
  head(20)
# create a bar plot
p2 <- ggplot(x_selected_byPopulation, mapping = aes(x=reorder(administrative_area_level_1, deathsByPopulation), deathsByPopulation, fill = administrative_area_level_1))
p2 + geom_bar(stat="identity") +
  guides(fill=FALSE) +
  xlab("Country") +
  ylab("Deaths/Population") +
  ggtitle("COVID-19 DEATHS / POPULATION") +
  coord_flip()

 

3.その他のグラフ

 

次にRによるグラフ作成のスクリプトが紹介されています。

 

R Interface to COVID-19 Data Hub

 

 

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.