Import libraries
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.3 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library (lubridate)
library (rvest)
Attaching package: 'rvest'
The following object is masked from 'package:readr':
guess_encoding
Attaching package: 'stringdist'
The following object is masked from 'package:tidyr':
extract
Attaching package: 'reshape2'
The following object is masked from 'package:tidyr':
smiths
존스홉킨스 대학의 COVID19 데이터를 가져오는 코드
clean_jhd_to_long <- function (df) {
df_str <- deparse (substitute (df))
var_str <- substr (df_str, 1 , str_length (df_str) - 4 )
df %>% group_by (` Country/Region ` ) %>%
filter (` Country/Region ` != "Cruise Ship" ) %>%
select (- ` Province/State ` , - Lat, - Long) %>%
mutate_at (vars (- group_cols ()), sum) %>%
distinct () %>%
ungroup () %>%
rename (country = ` Country/Region ` ) %>%
pivot_longer (
- country,
names_to = "date_str" ,
values_to = var_str
) %>%
mutate (date = mdy (date_str)) %>%
select (country, date, !! sym (var_str))
}
confirmed_raw <- read_csv ("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv" )
Rows: 289 Columns: 1147
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Province/State, Country/Region
dbl (1145): Lat, Long, 1/22/20, 1/23/20, 1/24/20, 1/25/20, 1/26/20, 1/27/20,...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
deaths_raw <- read_csv ("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv" )
Rows: 289 Columns: 1147
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Province/State, Country/Region
dbl (1145): Lat, Long, 1/22/20, 1/23/20, 1/24/20, 1/25/20, 1/26/20, 1/27/20,...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# A tibble: 6 × 1,147
`Province/State` `Country/Region` Lat Long `1/22/20` `1/23/20` `1/24/20`
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 <NA> Afghanistan 33.9 67.7 0 0 0
2 <NA> Albania 41.2 20.2 0 0 0
3 <NA> Algeria 28.0 1.66 0 0 0
4 <NA> Andorra 42.5 1.52 0 0 0
5 <NA> Angola -11.2 17.9 0 0 0
6 <NA> Antarctica -71.9 23.3 0 0 0
# ℹ 1,140 more variables: `1/25/20` <dbl>, `1/26/20` <dbl>, `1/27/20` <dbl>,
# `1/28/20` <dbl>, `1/29/20` <dbl>, `1/30/20` <dbl>, `1/31/20` <dbl>,
# `2/1/20` <dbl>, `2/2/20` <dbl>, `2/3/20` <dbl>, `2/4/20` <dbl>,
# `2/5/20` <dbl>, `2/6/20` <dbl>, `2/7/20` <dbl>, `2/8/20` <dbl>,
# `2/9/20` <dbl>, `2/10/20` <dbl>, `2/11/20` <dbl>, `2/12/20` <dbl>,
# `2/13/20` <dbl>, `2/14/20` <dbl>, `2/15/20` <dbl>, `2/16/20` <dbl>,
# `2/17/20` <dbl>, `2/18/20` <dbl>, `2/19/20` <dbl>, `2/20/20` <dbl>, …
confirmed_raw[confirmed_raw$ 'Country/Region' == "US" ,]
# A tibble: 1 × 1,147
`Province/State` `Country/Region` Lat Long `1/22/20` `1/23/20` `1/24/20`
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 <NA> US 40 -100 1 1 2
# ℹ 1,140 more variables: `1/25/20` <dbl>, `1/26/20` <dbl>, `1/27/20` <dbl>,
# `1/28/20` <dbl>, `1/29/20` <dbl>, `1/30/20` <dbl>, `1/31/20` <dbl>,
# `2/1/20` <dbl>, `2/2/20` <dbl>, `2/3/20` <dbl>, `2/4/20` <dbl>,
# `2/5/20` <dbl>, `2/6/20` <dbl>, `2/7/20` <dbl>, `2/8/20` <dbl>,
# `2/9/20` <dbl>, `2/10/20` <dbl>, `2/11/20` <dbl>, `2/12/20` <dbl>,
# `2/13/20` <dbl>, `2/14/20` <dbl>, `2/15/20` <dbl>, `2/16/20` <dbl>,
# `2/17/20` <dbl>, `2/18/20` <dbl>, `2/19/20` <dbl>, `2/20/20` <dbl>, …
[1] "Province/State" "Country/Region" "Lat" "Long"
[5] "1/22/20" "1/23/20" "1/24/20" "1/25/20"
[9] "1/26/20" "1/27/20" "1/28/20" "1/29/20"
[13] "1/30/20" "1/31/20" "2/1/20" "2/2/20"
[17] "2/3/20" "2/4/20" "2/5/20" "2/6/20"
[21] "2/7/20" "2/8/20" "2/9/20" "2/10/20"
[25] "2/11/20" "2/12/20" "2/13/20" "2/14/20"
[29] "2/15/20" "2/16/20" "2/17/20" "2/18/20"
[33] "2/19/20" "2/20/20" "2/21/20" "2/22/20"
[37] "2/23/20" "2/24/20" "2/25/20" "2/26/20"
[41] "2/27/20" "2/28/20" "2/29/20" "3/1/20"
[45] "3/2/20" "3/3/20" "3/4/20" "3/5/20"
[49] "3/6/20" "3/7/20" "3/8/20" "3/9/20"
[53] "3/10/20" "3/11/20" "3/12/20" "3/13/20"
[57] "3/14/20" "3/15/20" "3/16/20" "3/17/20"
[61] "3/18/20" "3/19/20" "3/20/20" "3/21/20"
[65] "3/22/20" "3/23/20" "3/24/20" "3/25/20"
[69] "3/26/20" "3/27/20" "3/28/20" "3/29/20"
[73] "3/30/20" "3/31/20" "4/1/20" "4/2/20"
[77] "4/3/20" "4/4/20" "4/5/20" "4/6/20"
[81] "4/7/20" "4/8/20" "4/9/20" "4/10/20"
[85] "4/11/20" "4/12/20" "4/13/20" "4/14/20"
[89] "4/15/20" "4/16/20" "4/17/20" "4/18/20"
[93] "4/19/20" "4/20/20" "4/21/20" "4/22/20"
[97] "4/23/20" "4/24/20" "4/25/20" "4/26/20"
[101] "4/27/20" "4/28/20" "4/29/20" "4/30/20"
[105] "5/1/20" "5/2/20" "5/3/20" "5/4/20"
[109] "5/5/20" "5/6/20" "5/7/20" "5/8/20"
[113] "5/9/20" "5/10/20" "5/11/20" "5/12/20"
[117] "5/13/20" "5/14/20" "5/15/20" "5/16/20"
[121] "5/17/20" "5/18/20" "5/19/20" "5/20/20"
[125] "5/21/20" "5/22/20" "5/23/20" "5/24/20"
[129] "5/25/20" "5/26/20" "5/27/20" "5/28/20"
[133] "5/29/20" "5/30/20" "5/31/20" "6/1/20"
[137] "6/2/20" "6/3/20" "6/4/20" "6/5/20"
[141] "6/6/20" "6/7/20" "6/8/20" "6/9/20"
[145] "6/10/20" "6/11/20" "6/12/20" "6/13/20"
[149] "6/14/20" "6/15/20" "6/16/20" "6/17/20"
[153] "6/18/20" "6/19/20" "6/20/20" "6/21/20"
[157] "6/22/20" "6/23/20" "6/24/20" "6/25/20"
[161] "6/26/20" "6/27/20" "6/28/20" "6/29/20"
[165] "6/30/20" "7/1/20" "7/2/20" "7/3/20"
[169] "7/4/20" "7/5/20" "7/6/20" "7/7/20"
[173] "7/8/20" "7/9/20" "7/10/20" "7/11/20"
[177] "7/12/20" "7/13/20" "7/14/20" "7/15/20"
[181] "7/16/20" "7/17/20" "7/18/20" "7/19/20"
[185] "7/20/20" "7/21/20" "7/22/20" "7/23/20"
[189] "7/24/20" "7/25/20" "7/26/20" "7/27/20"
[193] "7/28/20" "7/29/20" "7/30/20" "7/31/20"
[197] "8/1/20" "8/2/20" "8/3/20" "8/4/20"
[201] "8/5/20" "8/6/20" "8/7/20" "8/8/20"
[205] "8/9/20" "8/10/20" "8/11/20" "8/12/20"
[209] "8/13/20" "8/14/20" "8/15/20" "8/16/20"
[213] "8/17/20" "8/18/20" "8/19/20" "8/20/20"
[217] "8/21/20" "8/22/20" "8/23/20" "8/24/20"
[221] "8/25/20" "8/26/20" "8/27/20" "8/28/20"
[225] "8/29/20" "8/30/20" "8/31/20" "9/1/20"
[229] "9/2/20" "9/3/20" "9/4/20" "9/5/20"
[233] "9/6/20" "9/7/20" "9/8/20" "9/9/20"
[237] "9/10/20" "9/11/20" "9/12/20" "9/13/20"
[241] "9/14/20" "9/15/20" "9/16/20" "9/17/20"
[245] "9/18/20" "9/19/20" "9/20/20" "9/21/20"
[249] "9/22/20" "9/23/20" "9/24/20" "9/25/20"
[253] "9/26/20" "9/27/20" "9/28/20" "9/29/20"
[257] "9/30/20" "10/1/20" "10/2/20" "10/3/20"
[261] "10/4/20" "10/5/20" "10/6/20" "10/7/20"
[265] "10/8/20" "10/9/20" "10/10/20" "10/11/20"
[269] "10/12/20" "10/13/20" "10/14/20" "10/15/20"
[273] "10/16/20" "10/17/20" "10/18/20" "10/19/20"
[277] "10/20/20" "10/21/20" "10/22/20" "10/23/20"
[281] "10/24/20" "10/25/20" "10/26/20" "10/27/20"
[285] "10/28/20" "10/29/20" "10/30/20" "10/31/20"
[289] "11/1/20" "11/2/20" "11/3/20" "11/4/20"
[293] "11/5/20" "11/6/20" "11/7/20" "11/8/20"
[297] "11/9/20" "11/10/20" "11/11/20" "11/12/20"
[301] "11/13/20" "11/14/20" "11/15/20" "11/16/20"
[305] "11/17/20" "11/18/20" "11/19/20" "11/20/20"
[309] "11/21/20" "11/22/20" "11/23/20" "11/24/20"
[313] "11/25/20" "11/26/20" "11/27/20" "11/28/20"
[317] "11/29/20" "11/30/20" "12/1/20" "12/2/20"
[321] "12/3/20" "12/4/20" "12/5/20" "12/6/20"
[325] "12/7/20" "12/8/20" "12/9/20" "12/10/20"
[329] "12/11/20" "12/12/20" "12/13/20" "12/14/20"
[333] "12/15/20" "12/16/20" "12/17/20" "12/18/20"
[337] "12/19/20" "12/20/20" "12/21/20" "12/22/20"
[341] "12/23/20" "12/24/20" "12/25/20" "12/26/20"
[345] "12/27/20" "12/28/20" "12/29/20" "12/30/20"
[349] "12/31/20" "1/1/21" "1/2/21" "1/3/21"
[353] "1/4/21" "1/5/21" "1/6/21" "1/7/21"
[357] "1/8/21" "1/9/21" "1/10/21" "1/11/21"
[361] "1/12/21" "1/13/21" "1/14/21" "1/15/21"
[365] "1/16/21" "1/17/21" "1/18/21" "1/19/21"
[369] "1/20/21" "1/21/21" "1/22/21" "1/23/21"
[373] "1/24/21" "1/25/21" "1/26/21" "1/27/21"
[377] "1/28/21" "1/29/21" "1/30/21" "1/31/21"
[381] "2/1/21" "2/2/21" "2/3/21" "2/4/21"
[385] "2/5/21" "2/6/21" "2/7/21" "2/8/21"
[389] "2/9/21" "2/10/21" "2/11/21" "2/12/21"
[393] "2/13/21" "2/14/21" "2/15/21" "2/16/21"
[397] "2/17/21" "2/18/21" "2/19/21" "2/20/21"
[401] "2/21/21" "2/22/21" "2/23/21" "2/24/21"
[405] "2/25/21" "2/26/21" "2/27/21" "2/28/21"
[409] "3/1/21" "3/2/21" "3/3/21" "3/4/21"
[413] "3/5/21" "3/6/21" "3/7/21" "3/8/21"
[417] "3/9/21" "3/10/21" "3/11/21" "3/12/21"
[421] "3/13/21" "3/14/21" "3/15/21" "3/16/21"
[425] "3/17/21" "3/18/21" "3/19/21" "3/20/21"
[429] "3/21/21" "3/22/21" "3/23/21" "3/24/21"
[433] "3/25/21" "3/26/21" "3/27/21" "3/28/21"
[437] "3/29/21" "3/30/21" "3/31/21" "4/1/21"
[441] "4/2/21" "4/3/21" "4/4/21" "4/5/21"
[445] "4/6/21" "4/7/21" "4/8/21" "4/9/21"
[449] "4/10/21" "4/11/21" "4/12/21" "4/13/21"
[453] "4/14/21" "4/15/21" "4/16/21" "4/17/21"
[457] "4/18/21" "4/19/21" "4/20/21" "4/21/21"
[461] "4/22/21" "4/23/21" "4/24/21" "4/25/21"
[465] "4/26/21" "4/27/21" "4/28/21" "4/29/21"
[469] "4/30/21" "5/1/21" "5/2/21" "5/3/21"
[473] "5/4/21" "5/5/21" "5/6/21" "5/7/21"
[477] "5/8/21" "5/9/21" "5/10/21" "5/11/21"
[481] "5/12/21" "5/13/21" "5/14/21" "5/15/21"
[485] "5/16/21" "5/17/21" "5/18/21" "5/19/21"
[489] "5/20/21" "5/21/21" "5/22/21" "5/23/21"
[493] "5/24/21" "5/25/21" "5/26/21" "5/27/21"
[497] "5/28/21" "5/29/21" "5/30/21" "5/31/21"
[501] "6/1/21" "6/2/21" "6/3/21" "6/4/21"
[505] "6/5/21" "6/6/21" "6/7/21" "6/8/21"
[509] "6/9/21" "6/10/21" "6/11/21" "6/12/21"
[513] "6/13/21" "6/14/21" "6/15/21" "6/16/21"
[517] "6/17/21" "6/18/21" "6/19/21" "6/20/21"
[521] "6/21/21" "6/22/21" "6/23/21" "6/24/21"
[525] "6/25/21" "6/26/21" "6/27/21" "6/28/21"
[529] "6/29/21" "6/30/21" "7/1/21" "7/2/21"
[533] "7/3/21" "7/4/21" "7/5/21" "7/6/21"
[537] "7/7/21" "7/8/21" "7/9/21" "7/10/21"
[541] "7/11/21" "7/12/21" "7/13/21" "7/14/21"
[545] "7/15/21" "7/16/21" "7/17/21" "7/18/21"
[549] "7/19/21" "7/20/21" "7/21/21" "7/22/21"
[553] "7/23/21" "7/24/21" "7/25/21" "7/26/21"
[557] "7/27/21" "7/28/21" "7/29/21" "7/30/21"
[561] "7/31/21" "8/1/21" "8/2/21" "8/3/21"
[565] "8/4/21" "8/5/21" "8/6/21" "8/7/21"
[569] "8/8/21" "8/9/21" "8/10/21" "8/11/21"
[573] "8/12/21" "8/13/21" "8/14/21" "8/15/21"
[577] "8/16/21" "8/17/21" "8/18/21" "8/19/21"
[581] "8/20/21" "8/21/21" "8/22/21" "8/23/21"
[585] "8/24/21" "8/25/21" "8/26/21" "8/27/21"
[589] "8/28/21" "8/29/21" "8/30/21" "8/31/21"
[593] "9/1/21" "9/2/21" "9/3/21" "9/4/21"
[597] "9/5/21" "9/6/21" "9/7/21" "9/8/21"
[601] "9/9/21" "9/10/21" "9/11/21" "9/12/21"
[605] "9/13/21" "9/14/21" "9/15/21" "9/16/21"
[609] "9/17/21" "9/18/21" "9/19/21" "9/20/21"
[613] "9/21/21" "9/22/21" "9/23/21" "9/24/21"
[617] "9/25/21" "9/26/21" "9/27/21" "9/28/21"
[621] "9/29/21" "9/30/21" "10/1/21" "10/2/21"
[625] "10/3/21" "10/4/21" "10/5/21" "10/6/21"
[629] "10/7/21" "10/8/21" "10/9/21" "10/10/21"
[633] "10/11/21" "10/12/21" "10/13/21" "10/14/21"
[637] "10/15/21" "10/16/21" "10/17/21" "10/18/21"
[641] "10/19/21" "10/20/21" "10/21/21" "10/22/21"
[645] "10/23/21" "10/24/21" "10/25/21" "10/26/21"
[649] "10/27/21" "10/28/21" "10/29/21" "10/30/21"
[653] "10/31/21" "11/1/21" "11/2/21" "11/3/21"
[657] "11/4/21" "11/5/21" "11/6/21" "11/7/21"
[661] "11/8/21" "11/9/21" "11/10/21" "11/11/21"
[665] "11/12/21" "11/13/21" "11/14/21" "11/15/21"
[669] "11/16/21" "11/17/21" "11/18/21" "11/19/21"
[673] "11/20/21" "11/21/21" "11/22/21" "11/23/21"
[677] "11/24/21" "11/25/21" "11/26/21" "11/27/21"
[681] "11/28/21" "11/29/21" "11/30/21" "12/1/21"
[685] "12/2/21" "12/3/21" "12/4/21" "12/5/21"
[689] "12/6/21" "12/7/21" "12/8/21" "12/9/21"
[693] "12/10/21" "12/11/21" "12/12/21" "12/13/21"
[697] "12/14/21" "12/15/21" "12/16/21" "12/17/21"
[701] "12/18/21" "12/19/21" "12/20/21" "12/21/21"
[705] "12/22/21" "12/23/21" "12/24/21" "12/25/21"
[709] "12/26/21" "12/27/21" "12/28/21" "12/29/21"
[713] "12/30/21" "12/31/21" "1/1/22" "1/2/22"
[717] "1/3/22" "1/4/22" "1/5/22" "1/6/22"
[721] "1/7/22" "1/8/22" "1/9/22" "1/10/22"
[725] "1/11/22" "1/12/22" "1/13/22" "1/14/22"
[729] "1/15/22" "1/16/22" "1/17/22" "1/18/22"
[733] "1/19/22" "1/20/22" "1/21/22" "1/22/22"
[737] "1/23/22" "1/24/22" "1/25/22" "1/26/22"
[741] "1/27/22" "1/28/22" "1/29/22" "1/30/22"
[745] "1/31/22" "2/1/22" "2/2/22" "2/3/22"
[749] "2/4/22" "2/5/22" "2/6/22" "2/7/22"
[753] "2/8/22" "2/9/22" "2/10/22" "2/11/22"
[757] "2/12/22" "2/13/22" "2/14/22" "2/15/22"
[761] "2/16/22" "2/17/22" "2/18/22" "2/19/22"
[765] "2/20/22" "2/21/22" "2/22/22" "2/23/22"
[769] "2/24/22" "2/25/22" "2/26/22" "2/27/22"
[773] "2/28/22" "3/1/22" "3/2/22" "3/3/22"
[777] "3/4/22" "3/5/22" "3/6/22" "3/7/22"
[781] "3/8/22" "3/9/22" "3/10/22" "3/11/22"
[785] "3/12/22" "3/13/22" "3/14/22" "3/15/22"
[789] "3/16/22" "3/17/22" "3/18/22" "3/19/22"
[793] "3/20/22" "3/21/22" "3/22/22" "3/23/22"
[797] "3/24/22" "3/25/22" "3/26/22" "3/27/22"
[801] "3/28/22" "3/29/22" "3/30/22" "3/31/22"
[805] "4/1/22" "4/2/22" "4/3/22" "4/4/22"
[809] "4/5/22" "4/6/22" "4/7/22" "4/8/22"
[813] "4/9/22" "4/10/22" "4/11/22" "4/12/22"
[817] "4/13/22" "4/14/22" "4/15/22" "4/16/22"
[821] "4/17/22" "4/18/22" "4/19/22" "4/20/22"
[825] "4/21/22" "4/22/22" "4/23/22" "4/24/22"
[829] "4/25/22" "4/26/22" "4/27/22" "4/28/22"
[833] "4/29/22" "4/30/22" "5/1/22" "5/2/22"
[837] "5/3/22" "5/4/22" "5/5/22" "5/6/22"
[841] "5/7/22" "5/8/22" "5/9/22" "5/10/22"
[845] "5/11/22" "5/12/22" "5/13/22" "5/14/22"
[849] "5/15/22" "5/16/22" "5/17/22" "5/18/22"
[853] "5/19/22" "5/20/22" "5/21/22" "5/22/22"
[857] "5/23/22" "5/24/22" "5/25/22" "5/26/22"
[861] "5/27/22" "5/28/22" "5/29/22" "5/30/22"
[865] "5/31/22" "6/1/22" "6/2/22" "6/3/22"
[869] "6/4/22" "6/5/22" "6/6/22" "6/7/22"
[873] "6/8/22" "6/9/22" "6/10/22" "6/11/22"
[877] "6/12/22" "6/13/22" "6/14/22" "6/15/22"
[881] "6/16/22" "6/17/22" "6/18/22" "6/19/22"
[885] "6/20/22" "6/21/22" "6/22/22" "6/23/22"
[889] "6/24/22" "6/25/22" "6/26/22" "6/27/22"
[893] "6/28/22" "6/29/22" "6/30/22" "7/1/22"
[897] "7/2/22" "7/3/22" "7/4/22" "7/5/22"
[901] "7/6/22" "7/7/22" "7/8/22" "7/9/22"
[905] "7/10/22" "7/11/22" "7/12/22" "7/13/22"
[909] "7/14/22" "7/15/22" "7/16/22" "7/17/22"
[913] "7/18/22" "7/19/22" "7/20/22" "7/21/22"
[917] "7/22/22" "7/23/22" "7/24/22" "7/25/22"
[921] "7/26/22" "7/27/22" "7/28/22" "7/29/22"
[925] "7/30/22" "7/31/22" "8/1/22" "8/2/22"
[929] "8/3/22" "8/4/22" "8/5/22" "8/6/22"
[933] "8/7/22" "8/8/22" "8/9/22" "8/10/22"
[937] "8/11/22" "8/12/22" "8/13/22" "8/14/22"
[941] "8/15/22" "8/16/22" "8/17/22" "8/18/22"
[945] "8/19/22" "8/20/22" "8/21/22" "8/22/22"
[949] "8/23/22" "8/24/22" "8/25/22" "8/26/22"
[953] "8/27/22" "8/28/22" "8/29/22" "8/30/22"
[957] "8/31/22" "9/1/22" "9/2/22" "9/3/22"
[961] "9/4/22" "9/5/22" "9/6/22" "9/7/22"
[965] "9/8/22" "9/9/22" "9/10/22" "9/11/22"
[969] "9/12/22" "9/13/22" "9/14/22" "9/15/22"
[973] "9/16/22" "9/17/22" "9/18/22" "9/19/22"
[977] "9/20/22" "9/21/22" "9/22/22" "9/23/22"
[981] "9/24/22" "9/25/22" "9/26/22" "9/27/22"
[985] "9/28/22" "9/29/22" "9/30/22" "10/1/22"
[989] "10/2/22" "10/3/22" "10/4/22" "10/5/22"
[993] "10/6/22" "10/7/22" "10/8/22" "10/9/22"
[997] "10/10/22" "10/11/22" "10/12/22" "10/13/22"
[1001] "10/14/22" "10/15/22" "10/16/22" "10/17/22"
[1005] "10/18/22" "10/19/22" "10/20/22" "10/21/22"
[1009] "10/22/22" "10/23/22" "10/24/22" "10/25/22"
[1013] "10/26/22" "10/27/22" "10/28/22" "10/29/22"
[1017] "10/30/22" "10/31/22" "11/1/22" "11/2/22"
[1021] "11/3/22" "11/4/22" "11/5/22" "11/6/22"
[1025] "11/7/22" "11/8/22" "11/9/22" "11/10/22"
[1029] "11/11/22" "11/12/22" "11/13/22" "11/14/22"
[1033] "11/15/22" "11/16/22" "11/17/22" "11/18/22"
[1037] "11/19/22" "11/20/22" "11/21/22" "11/22/22"
[1041] "11/23/22" "11/24/22" "11/25/22" "11/26/22"
[1045] "11/27/22" "11/28/22" "11/29/22" "11/30/22"
[1049] "12/1/22" "12/2/22" "12/3/22" "12/4/22"
[1053] "12/5/22" "12/6/22" "12/7/22" "12/8/22"
[1057] "12/9/22" "12/10/22" "12/11/22" "12/12/22"
[1061] "12/13/22" "12/14/22" "12/15/22" "12/16/22"
[1065] "12/17/22" "12/18/22" "12/19/22" "12/20/22"
[1069] "12/21/22" "12/22/22" "12/23/22" "12/24/22"
[1073] "12/25/22" "12/26/22" "12/27/22" "12/28/22"
[1077] "12/29/22" "12/30/22" "12/31/22" "1/1/23"
[1081] "1/2/23" "1/3/23" "1/4/23" "1/5/23"
[1085] "1/6/23" "1/7/23" "1/8/23" "1/9/23"
[1089] "1/10/23" "1/11/23" "1/12/23" "1/13/23"
[1093] "1/14/23" "1/15/23" "1/16/23" "1/17/23"
[1097] "1/18/23" "1/19/23" "1/20/23" "1/21/23"
[1101] "1/22/23" "1/23/23" "1/24/23" "1/25/23"
[1105] "1/26/23" "1/27/23" "1/28/23" "1/29/23"
[1109] "1/30/23" "1/31/23" "2/1/23" "2/2/23"
[1113] "2/3/23" "2/4/23" "2/5/23" "2/6/23"
[1117] "2/7/23" "2/8/23" "2/9/23" "2/10/23"
[1121] "2/11/23" "2/12/23" "2/13/23" "2/14/23"
[1125] "2/15/23" "2/16/23" "2/17/23" "2/18/23"
[1129] "2/19/23" "2/20/23" "2/21/23" "2/22/23"
[1133] "2/23/23" "2/24/23" "2/25/23" "2/26/23"
[1137] "2/27/23" "2/28/23" "3/1/23" "3/2/23"
[1141] "3/3/23" "3/4/23" "3/5/23" "3/6/23"
[1145] "3/7/23" "3/8/23" "3/9/23"
확진자 데이터 프레임을 만들어 보자.
confirmed_raw %>%
filter (` Country/Region ` %in% c ("China" , "Italy" , "Japan" , "United Kingdom" , "US" , "Korea, South" ,
"Spain" )) %>%
select (- c (` Province/State ` , Lat, Long)) %>%
group_by (` Country/Region ` ) %>% summarise_all (sum) -> test
names (test)[1 ]<- "country"
melt (data = test, id.vars = "country" , measure.vars = names (test)[- 1 ]) %>%
separate (variable, into = c ("mon" , "day" , "year" ), sep= '/' , extra = "merge" ) %>%
filter (day %in% c (1 )) %>%
arrange (mon, day) %>%
mutate (date= as.Date (with (.,paste (mon, day, year, sep= "/" )), format = "%m/%d/%y" )) %>%
dcast (country ~ date) -> df.conf.case
country 2020-02-01 2020-03-01 2020-04-01 2020-05-01 2020-06-01
1 China 11891 79932 84002 86850 87520
2 Italy 2 1694 110574 207428 233197
3 Japan 20 259 2535 14558 16778
4 Korea, South 12 3736 9887 10780 11541
5 Spain 1 84 104118 215216 239638
6 United Kingdom 2 94 43755 183500 258979
7 US 8 32 227903 1115972 1809384
2020-07-01 2020-08-01 2020-09-01 2020-10-01 2020-11-01 2020-12-01 2021-01-01
1 88344 91690 94363 95568 97250 99336 102649
2 240760 247832 270189 317409 709335 1620901 2129376
3 18732 37790 69018 84212 101936 150857 239005
4 12904 14366 20449 23952 26732 35163 62593
5 249659 288522 470973 778607 1185678 1656444 1928265
6 285276 305558 339403 462780 1038056 1647165 2549671
7 2698127 4605921 6088458 7292562 9254490 13866746 20397398
2021-02-01 2021-03-01 2021-04-01 2021-05-01 2021-06-01 2021-07-01 2021-08-01
1 107902 109034 110169 111325 112329 113614 115473
2 2560957 2938371 3607083 4035617 4220304 4260788 4355348
3 392533 433334 477691 598754 749126 801337 936852
4 78844 90372 104194 123240 141476 158549 201002
5 2822805 3204531 3291394 3524077 3682778 3821305 4447044
6 3846807 4194287 4364544 4434156 4506331 4844879 5907641
7 26482919 28814420 30656330 32516226 33407540 33797251 35152818
2021-09-01 2021-10-01 2021-11-01 2021-12-01 2022-01-01 2022-02-01 2022-03-01
1 117991 119790 121477 123725 128132 134564 456582
2 4546487 4675758 4774783 5043620 6266939 11116422 12829972
3 1514400 1706516 1722427 1726913 1733835 2825414 5078276
4 255401 316020 367974 457612 639083 884310 3492686
5 4861883 4961128 5011148 5174720 6294745 10039126 11036085
6 6856890 7878555 9140352 10333452 13174530 17543963 19120746
7 39585475 43694428 46163201 48743340 55099948 75570589 79228450
2022-04-01 2022-05-01 2022-06-01 2022-07-01 2022-08-01 2022-09-01 2022-10-01
1 1400358 2024284 2097282 2137169 2265424 2510703 2762150
2 14719394 16504791 17440232 18610011 21059545 21888255 22500346
3 6614278 7910179 8876113 9355427 12935010 19116684 21329519
4 13639915 17295733 18129313 18379552 19932439 23417425 24819611
5 11551574 11896152 12360256 12818184 13226579 13342530 13422984
6 21379545 22214004 22492903 22941360 23515928 23738035 23893496
7 80252748 81483804 84556267 87832253 91515236 94659072 96369625
2022-11-01 2022-12-01 2023-01-01 2023-02-01 2023-03-01
1 2959481 3764783 4612203 4903498 4903524
2 23531023 24260660 25143705 25453789 25576852
3 22389872 24933509 29321601 32610584 33241180
4 25670407 27208800 29139535 30213928 30533573
5 13511768 13595504 13684258 13731478 13763336
6 24122922 24251636 24365688 24507372 24603450
7 97540736 98903928 100769628 102479379 103533872
사망자 데이터 프레임을 만들어 보자.
deaths_raw %>%
filter (` Country/Region ` %in% c ("China" , "Italy" , "Japan" , "United Kingdom" , "US" , "Korea, South" ,
"Spain" )) %>%
select (- c (` Province/State ` , Lat, Long)) %>%
group_by (` Country/Region ` ) %>% summarise_all (sum) -> test
names (test)[1 ]<- "country"
melt (data = test, id.vars = "country" , measure.vars = names (test)[- 1 ]) %>%
separate (variable, into = c ("mon" , "day" , "year" ), sep= '/' , extra = "merge" ) %>%
filter (day %in% c (1 )) %>%
arrange (mon, day) %>%
mutate (date= as.Date (with (.,paste (mon, day, year, sep= "/" )), format = "%m/%d/%y" )) %>%
dcast (country ~ date) -> df.death.case
country 2020-02-01 2020-03-01 2020-04-01 2020-05-01 2020-06-01
1 China 259 2872 3332 4698 4708
2 Italy 0 34 13155 28236 33475
3 Japan 0 6 72 510 900
4 Korea, South 0 17 165 250 272
5 Spain 0 0 9387 24543 27127
6 United Kingdom 1 3 6070 39849 52768
7 US 0 1 6996 68518 108624
2020-07-01 2020-08-01 2020-09-01 2020-10-01 2020-11-01 2020-12-01 2021-01-01
1 4713 4737 4797 4813 4814 4830 4884
2 34788 35146 35491 35918 38826 56361 74621
3 976 1013 1314 1583 1776 2193 3541
4 282 301 326 416 468 526 942
5 28364 28445 29152 31973 35878 45511 50837
6 56338 57454 57995 58946 64667 78184 95917
7 128134 155059 183855 206852 231054 273099 352844
2021-02-01 2021-03-01 2021-04-01 2021-05-01 2021-06-01 2021-07-01 2021-08-01
1 4966 5011 5023 5031 5031 5033 5047
2 88845 97945 109847 121033 126221 127587 128068
3 5833 7948 9194 10326 13160 14808 15198
4 1435 1606 1737 1833 1965 2024 2099
5 59081 69609 75541 78216 79983 80883 81486
6 132799 148935 153012 154085 154509 155010 156941
7 448381 513045 549448 572904 590904 600972 609715
2021-09-01 2021-10-01 2021-11-01 2021-12-01 2022-01-01 2022-02-01 2022-03-01
1 5056 5069 5081 5089 5103 5119 5901
2 129290 130973 132120 133931 137513 146925 155000
3 16138 17685 18274 18361 18392 18885 23908
4 2303 2504 2874 3705 5694 6787 8266
5 84472 86463 87368 88080 89405 93633 99883
6 160317 164780 169438 173903 178046 184840 188681
7 639812 699021 746135 781422 825870 892252 952086
2022-04-01 2022-05-01 2022-06-01 2022-07-01 2022-08-01 2022-09-01 2022-10-01
1 12869 14697 14899 14928 15052 15251 15719
2 159537 163612 166756 168425 172207 175663 177130
3 28202 29605 30659 31302 32707 40245 45023
4 16929 22958 24212 24562 25084 26940 28489
5 102541 104456 106493 108111 110719 112600 114179
6 193232 198276 200347 201869 205574 207875 209346
7 983972 996109 1007741 1017872 1030654 1046956 1059542
2022-11-01 2022-12-01 2023-01-01 2023-02-01 2023-03-01
1 15965 16001 17167 97668 101051
2 179101 181098 184642 186833 188094
3 46817 49834 57521 68407 72494
4 29239 30621 32272 33522 34003
5 115078 115901 117095 118434 119380
6 212435 214234 217175 220129 220721
7 1070821 1081153 1092779 1109996 1120897
확진자, 사망자 데이터 프레임을 행렬로 만들어보자.¶
# country.name<-c("China","Italy","Japan","Korea","Spain","UK","US")
country.name<- unlist (df.conf.case[c (1 )])
#str(df.conf.case)
m.conf.case<- as.matrix (df.conf.case[- 1 ])
row.names (m.conf.case)<- country.name
m.death.case<- as.matrix (df.death.case[- 1 ])
row.names (m.death.case)= country.name
m.death.rate<- round (m.death.case/ m.conf.case, 2 )
확진자 행렬: m.conf.case
사망자 행렬: m.death.case
2020-02-01 2020-03-01 2020-04-01 2020-05-01 2020-06-01
China 11891 79932 84002 86850 87520
Italy 2 1694 110574 207428 233197
Japan 20 259 2535 14558 16778
Korea, South 12 3736 9887 10780 11541
Spain 1 84 104118 215216 239638
United Kingdom 2 94 43755 183500 258979
US 8 32 227903 1115972 1809384
2020-07-01 2020-08-01 2020-09-01 2020-10-01 2020-11-01
China 88344 91690 94363 95568 97250
Italy 240760 247832 270189 317409 709335
Japan 18732 37790 69018 84212 101936
Korea, South 12904 14366 20449 23952 26732
Spain 249659 288522 470973 778607 1185678
United Kingdom 285276 305558 339403 462780 1038056
US 2698127 4605921 6088458 7292562 9254490
2020-12-01 2021-01-01 2021-02-01 2021-03-01 2021-04-01
China 99336 102649 107902 109034 110169
Italy 1620901 2129376 2560957 2938371 3607083
Japan 150857 239005 392533 433334 477691
Korea, South 35163 62593 78844 90372 104194
Spain 1656444 1928265 2822805 3204531 3291394
United Kingdom 1647165 2549671 3846807 4194287 4364544
US 13866746 20397398 26482919 28814420 30656330
2021-05-01 2021-06-01 2021-07-01 2021-08-01 2021-09-01
China 111325 112329 113614 115473 117991
Italy 4035617 4220304 4260788 4355348 4546487
Japan 598754 749126 801337 936852 1514400
Korea, South 123240 141476 158549 201002 255401
Spain 3524077 3682778 3821305 4447044 4861883
United Kingdom 4434156 4506331 4844879 5907641 6856890
US 32516226 33407540 33797251 35152818 39585475
2021-10-01 2021-11-01 2021-12-01 2022-01-01 2022-02-01
China 119790 121477 123725 128132 134564
Italy 4675758 4774783 5043620 6266939 11116422
Japan 1706516 1722427 1726913 1733835 2825414
Korea, South 316020 367974 457612 639083 884310
Spain 4961128 5011148 5174720 6294745 10039126
United Kingdom 7878555 9140352 10333452 13174530 17543963
US 43694428 46163201 48743340 55099948 75570589
2022-03-01 2022-04-01 2022-05-01 2022-06-01 2022-07-01
China 456582 1400358 2024284 2097282 2137169
Italy 12829972 14719394 16504791 17440232 18610011
Japan 5078276 6614278 7910179 8876113 9355427
Korea, South 3492686 13639915 17295733 18129313 18379552
Spain 11036085 11551574 11896152 12360256 12818184
United Kingdom 19120746 21379545 22214004 22492903 22941360
US 79228450 80252748 81483804 84556267 87832253
2022-08-01 2022-09-01 2022-10-01 2022-11-01 2022-12-01
China 2265424 2510703 2762150 2959481 3764783
Italy 21059545 21888255 22500346 23531023 24260660
Japan 12935010 19116684 21329519 22389872 24933509
Korea, South 19932439 23417425 24819611 25670407 27208800
Spain 13226579 13342530 13422984 13511768 13595504
United Kingdom 23515928 23738035 23893496 24122922 24251636
US 91515236 94659072 96369625 97540736 98903928
2023-01-01 2023-02-01 2023-03-01
China 4612203 4903498 4903524
Italy 25143705 25453789 25576852
Japan 29321601 32610584 33241180
Korea, South 29139535 30213928 30533573
Spain 13684258 13731478 13763336
United Kingdom 24365688 24507372 24603450
US 100769628 102479379 103533872
2020-02-01 2020-03-01 2020-04-01 2020-05-01 2020-06-01
China 259 2872 3332 4698 4708
Italy 0 34 13155 28236 33475
Japan 0 6 72 510 900
Korea, South 0 17 165 250 272
Spain 0 0 9387 24543 27127
United Kingdom 1 3 6070 39849 52768
US 0 1 6996 68518 108624
2020-07-01 2020-08-01 2020-09-01 2020-10-01 2020-11-01
China 4713 4737 4797 4813 4814
Italy 34788 35146 35491 35918 38826
Japan 976 1013 1314 1583 1776
Korea, South 282 301 326 416 468
Spain 28364 28445 29152 31973 35878
United Kingdom 56338 57454 57995 58946 64667
US 128134 155059 183855 206852 231054
2020-12-01 2021-01-01 2021-02-01 2021-03-01 2021-04-01
China 4830 4884 4966 5011 5023
Italy 56361 74621 88845 97945 109847
Japan 2193 3541 5833 7948 9194
Korea, South 526 942 1435 1606 1737
Spain 45511 50837 59081 69609 75541
United Kingdom 78184 95917 132799 148935 153012
US 273099 352844 448381 513045 549448
2021-05-01 2021-06-01 2021-07-01 2021-08-01 2021-09-01
China 5031 5031 5033 5047 5056
Italy 121033 126221 127587 128068 129290
Japan 10326 13160 14808 15198 16138
Korea, South 1833 1965 2024 2099 2303
Spain 78216 79983 80883 81486 84472
United Kingdom 154085 154509 155010 156941 160317
US 572904 590904 600972 609715 639812
2021-10-01 2021-11-01 2021-12-01 2022-01-01 2022-02-01
China 5069 5081 5089 5103 5119
Italy 130973 132120 133931 137513 146925
Japan 17685 18274 18361 18392 18885
Korea, South 2504 2874 3705 5694 6787
Spain 86463 87368 88080 89405 93633
United Kingdom 164780 169438 173903 178046 184840
US 699021 746135 781422 825870 892252
2022-03-01 2022-04-01 2022-05-01 2022-06-01 2022-07-01
China 5901 12869 14697 14899 14928
Italy 155000 159537 163612 166756 168425
Japan 23908 28202 29605 30659 31302
Korea, South 8266 16929 22958 24212 24562
Spain 99883 102541 104456 106493 108111
United Kingdom 188681 193232 198276 200347 201869
US 952086 983972 996109 1007741 1017872
2022-08-01 2022-09-01 2022-10-01 2022-11-01 2022-12-01
China 15052 15251 15719 15965 16001
Italy 172207 175663 177130 179101 181098
Japan 32707 40245 45023 46817 49834
Korea, South 25084 26940 28489 29239 30621
Spain 110719 112600 114179 115078 115901
United Kingdom 205574 207875 209346 212435 214234
US 1030654 1046956 1059542 1070821 1081153
2023-01-01 2023-02-01 2023-03-01
China 17167 97668 101051
Italy 184642 186833 188094
Japan 57521 68407 72494
Korea, South 32272 33522 34003
Spain 117095 118434 119380
United Kingdom 217175 220129 220721
US 1092779 1109996 1120897
선정된 국가에 대한 인구 벡터를 만들어 봅시다. 국가 이름 벡터. 인구 벡터에 이름을 붙여주기 위해 생성
country1 country2 country3 country4
"China" "Italy" "Japan" "Korea, South"
country5 country6 country7
"Spain" "United Kingdom" "US"
선정된 국가 순서대로 인구 수를 입력한 벡터
pop<- c (1439323776 , 60461826 , 126476461 , 51269185 , 46754778 , 67886011 , 331002651 )
pop
[1] 1439323776 60461826 126476461 51269185 46754778 67886011 331002651
아직은 벡터 값들에 이름이 붙어 있지 않은 것을 알 수 있다.
pop 벡터에 각 인구수가 어느 국가이 인구수인지 names() 함수로 지정해줌
pop<- c (1439323776 , 60461826 , 126476461 , 51269185 , 46754778 , 67886011 , 331002651 )
names (pop)<- country.name
pop
China Italy Japan Korea, South Spain
1439323776 60461826 126476461 51269185 46754778
United Kingdom US
67886011 331002651
GDP 벡터를 만들어 봅시다 - 마찬가지로 names() 함수로 GDP가 어느 국가에 해당하는 GDP인지에 대한 정보를 준다.
# round(m.conf.case/pop*1000, 2)
country.name<- c ("China" ,"Italy" ,"Japan" ,"Korea" ,"Spain" ,"UK" ,"US" )
GDP<- c (12237700479375 ,
1943835376342 ,
4872415104315 ,
1530750923149 ,
1314314164402 ,
2637866340434 ,
19485394000000 )
names (GDP)<- country.name
GDP
China Italy Japan Korea Spain UK
1.223770e+13 1.943835e+12 4.872415e+12 1.530751e+12 1.314314e+12 2.637866e+12
US
1.948539e+13
선정된 국가에 대한 인구밀도 벡터를 만들어 봅시다.
country.name<- c ("China" ,"Italy" ,"Japan" ,"Korea" ,"Spain" ,"UK" ,"US" )
pop.density<- c (148 , 205 , 347 , 530 , 94 , 275 , 36 )
names (pop.density)<- country.name
각국의 GDP 시각화를 해보자.
barplot (sort (GDP, decreasing = T))