Load the libraries
# Load the readr, ggplot2, and dplyr packages
library(readr)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
IMPORT RAW DATA: Johns Hopkins Github data
confirmedraw <- 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")
str(confirmedraw) # Check latest date at the end of data
## 'data.frame': 275 obs. of 483 variables:
## $ Province.State: chr "" "" "" "" ...
## $ Country.Region: chr "Afghanistan" "Albania" "Algeria" "Andorra" ...
## $ Lat : num 33.9 41.2 28 42.5 -11.2 ...
## $ Long : num 67.71 20.17 1.66 1.52 17.87 ...
## $ X1.22.20 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ X1.23.20 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ X1.24.20 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ X1.25.20 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ X1.26.20 : int 0 0 0 0 0 0 0 0 0 3 ...
## $ X1.27.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X1.28.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X1.29.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X1.30.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X1.31.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.1.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.2.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.3.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.4.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.5.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.6.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.7.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.8.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.9.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.10.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.11.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.12.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.13.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.14.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.15.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.16.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.17.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.18.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.19.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.20.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.21.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.22.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.23.20 : int 0 0 0 0 0 0 0 0 0 4 ...
## $ X2.24.20 : int 1 0 0 0 0 0 0 0 0 4 ...
## $ X2.25.20 : int 1 0 1 0 0 0 0 0 0 4 ...
## $ X2.26.20 : int 1 0 1 0 0 0 0 0 0 4 ...
## $ X2.27.20 : int 1 0 1 0 0 0 0 0 0 4 ...
## $ X2.28.20 : int 1 0 1 0 0 0 0 0 0 4 ...
## $ X2.29.20 : int 1 0 1 0 0 0 0 0 0 4 ...
## $ X3.1.20 : int 1 0 1 0 0 0 0 1 0 6 ...
## $ X3.2.20 : int 1 0 3 1 0 0 0 1 0 6 ...
## $ X3.3.20 : int 2 0 5 1 0 0 1 1 0 13 ...
## $ X3.4.20 : int 4 0 12 1 0 0 1 1 0 22 ...
## $ X3.5.20 : int 4 0 12 1 0 0 1 1 0 22 ...
## $ X3.6.20 : int 4 0 17 1 0 0 2 1 0 26 ...
## $ X3.7.20 : int 4 0 17 1 0 0 8 1 0 28 ...
## $ X3.8.20 : int 5 0 19 1 0 0 12 1 0 38 ...
## $ X3.9.20 : int 7 2 20 1 0 0 12 1 0 48 ...
## $ X3.10.20 : int 8 10 20 1 0 0 17 1 0 55 ...
## $ X3.11.20 : int 11 12 20 1 0 0 19 1 0 65 ...
## $ X3.12.20 : int 12 23 24 1 0 0 19 4 0 65 ...
## $ X3.13.20 : int 13 33 26 1 0 1 31 8 1 92 ...
## $ X3.14.20 : int 15 38 37 1 0 1 34 18 1 112 ...
## $ X3.15.20 : int 16 42 48 1 0 1 45 26 1 134 ...
## $ X3.16.20 : int 18 51 54 2 0 1 56 52 2 171 ...
## $ X3.17.20 : int 20 55 60 39 0 1 68 78 2 210 ...
## $ X3.18.20 : int 24 59 74 39 0 1 79 84 3 267 ...
## $ X3.19.20 : int 25 64 87 53 0 1 97 115 4 307 ...
## $ X3.20.20 : int 29 70 90 75 1 1 128 136 6 353 ...
## $ X3.21.20 : int 30 76 139 88 2 1 158 160 9 436 ...
## $ X3.22.20 : int 34 89 201 113 2 1 266 194 19 669 ...
## $ X3.23.20 : int 41 104 230 133 3 3 301 235 32 669 ...
## $ X3.24.20 : int 43 123 264 164 3 3 387 249 39 818 ...
## $ X3.25.20 : int 76 146 302 188 3 3 387 265 39 1029 ...
## $ X3.26.20 : int 80 174 367 224 4 7 502 290 53 1219 ...
## $ X3.27.20 : int 91 186 409 267 4 7 589 329 62 1405 ...
## $ X3.28.20 : int 107 197 454 308 5 7 690 407 71 1617 ...
## $ X3.29.20 : int 118 212 511 334 7 7 745 424 77 1791 ...
## $ X3.30.20 : int 146 223 584 370 7 7 820 482 78 2032 ...
## $ X3.31.20 : int 175 243 716 376 7 7 1054 532 80 2032 ...
## $ X4.1.20 : int 197 259 847 390 8 7 1054 571 84 2182 ...
## $ X4.2.20 : int 240 277 986 428 8 9 1133 663 87 2298 ...
## $ X4.3.20 : int 275 304 1171 439 8 15 1265 736 91 2389 ...
## $ X4.4.20 : int 300 333 1251 466 10 15 1451 770 93 2493 ...
## $ X4.5.20 : int 338 361 1320 501 14 15 1451 822 96 2580 ...
## $ X4.6.20 : int 368 377 1423 525 16 15 1554 833 96 2637 ...
## $ X4.7.20 : int 424 383 1468 545 17 19 1628 853 96 2686 ...
## $ X4.8.20 : int 445 400 1572 564 19 19 1715 881 99 2734 ...
## $ X4.9.20 : int 485 409 1666 583 19 19 1795 921 100 2773 ...
## $ X4.10.20 : int 532 416 1761 601 19 19 1975 937 103 2822 ...
## $ X4.11.20 : int 556 433 1825 601 19 21 1975 967 103 2857 ...
## $ X4.12.20 : int 608 446 1914 638 19 21 2142 1013 103 2857 ...
## $ X4.13.20 : int 666 467 1983 646 19 23 2208 1039 102 2863 ...
## $ X4.14.20 : int 715 475 2070 659 19 23 2277 1067 103 2870 ...
## $ X4.15.20 : int 785 494 2160 673 19 23 2443 1111 103 2886 ...
## $ X4.16.20 : int 841 518 2268 673 19 23 2571 1159 103 2897 ...
## $ X4.17.20 : int 907 539 2418 696 19 23 2669 1201 103 2926 ...
## $ X4.18.20 : int 934 548 2534 704 24 23 2758 1248 103 2936 ...
## $ X4.19.20 : int 997 562 2629 713 24 23 2839 1291 103 2957 ...
## $ X4.20.20 : int 1027 584 2718 717 24 23 2941 1339 104 2963 ...
## $ X4.21.20 : int 1093 609 2811 717 24 23 3031 1401 104 2969 ...
## $ X4.22.20 : int 1177 634 2910 723 25 24 3144 1473 104 2971 ...
## $ X4.23.20 : int 1236 663 3007 723 25 24 3435 1523 104 2976 ...
## $ X4.24.20 : int 1331 678 3127 731 25 24 3607 1596 105 2982 ...
## $ X4.25.20 : int 1464 712 3256 738 25 24 3780 1677 106 2994 ...
## [list output truncated]
deathsraw <- 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")
recoveredraw <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv")
# Note differences in the number of rows/columns
DATA CLEANING: To create country level and global combined data Convert each data set from wide to long AND aggregate at country level
library(tidyr)
library(dplyr)
confirmed <- confirmedraw %>% gather(key="date", value="confirmed", -c(Country.Region, Province.State, Lat, Long)) %>% group_by(Country.Region, date) %>% summarize(confirmed=sum(confirmed))
## `summarise()` has grouped output by 'Country.Region'. You can override using the `.groups` argument.
deaths <- deathsraw %>% gather(key="date", value="deaths", -c(Country.Region, Province.State, Lat, Long)) %>% group_by(Country.Region, date) %>% summarize(deaths=sum(deaths))
## `summarise()` has grouped output by 'Country.Region'. You can override using the `.groups` argument.
recovered <- recoveredraw %>% gather(key="date", value="recovered", -c(Country.Region, Province.State, Lat, Long)) %>% group_by(Country.Region, date) %>% summarize(recovered=sum(recovered))
## `summarise()` has grouped output by 'Country.Region'. You can override using the `.groups` argument.
summary(confirmed)
## Country.Region date confirmed
## Length:91968 Length:91968 Min. : 0
## Class :character Class :character 1st Qu.: 220
## Mode :character Mode :character Median : 5787
## Mean : 258312
## 3rd Qu.: 78334
## Max. :32895169
DATA COMBINING
# Final data: combine all three
country <- full_join(confirmed, deaths) %>% full_join(recovered)
## Joining, by = c("Country.Region", "date")
## Joining, by = c("Country.Region", "date")
# Date variable
# Fix date variable and convert from character to date
str(country) # check date character
## grouped_df[,5] [91,968 × 5] (S3: grouped_df/tbl_df/tbl/data.frame)
## $ Country.Region: chr [1:91968] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
## $ date : chr [1:91968] "X1.1.21" "X1.10.21" "X1.11.21" "X1.12.21" ...
## $ confirmed : int [1:91968] 51526 53489 53538 53584 53584 53775 53831 53938 53984 54062 ...
## $ deaths : int [1:91968] 2191 2277 2288 2301 2301 2314 2324 2336 2339 2343 ...
## $ recovered : int [1:91968] 41727 43948 44137 44608 44850 45298 45434 45465 45868 46359 ...
## - attr(*, "groups")= tibble[,2] [192 × 2] (S3: tbl_df/tbl/data.frame)
## ..$ Country.Region: chr [1:192] "Afghanistan" "Albania" "Algeria" "Andorra" ...
## ..$ .rows : list<int> [1:192]
## .. ..$ : int [1:479] 1 2 3 4 5 6 7 8 9 10 ...
## .. ..$ : int [1:479] 480 481 482 483 484 485 486 487 488 489 ...
## .. ..$ : int [1:479] 959 960 961 962 963 964 965 966 967 968 ...
## .. ..$ : int [1:479] 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 ...
## .. ..$ : int [1:479] 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 ...
## .. ..$ : int [1:479] 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 ...
## .. ..$ : int [1:479] 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 ...
## .. ..$ : int [1:479] 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 ...
## .. ..$ : int [1:479] 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 ...
## .. ..$ : int [1:479] 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 ...
## .. ..$ : int [1:479] 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 ...
## .. ..$ : int [1:479] 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 ...
## .. ..$ : int [1:479] 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 ...
## .. ..$ : int [1:479] 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 ...
## .. ..$ : int [1:479] 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 ...
## .. ..$ : int [1:479] 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 ...
## .. ..$ : int [1:479] 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 ...
## .. ..$ : int [1:479] 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 ...
## .. ..$ : int [1:479] 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 ...
## .. ..$ : int [1:479] 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 ...
## .. ..$ : int [1:479] 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 ...
## .. ..$ : int [1:479] 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 ...
## .. ..$ : int [1:479] 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 ...
## .. ..$ : int [1:479] 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 ...
## .. ..$ : int [1:479] 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 ...
## .. ..$ : int [1:479] 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 ...
## .. ..$ : int [1:479] 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 ...
## .. ..$ : int [1:479] 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 ...
## .. ..$ : int [1:479] 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 ...
## .. ..$ : int [1:479] 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 ...
## .. ..$ : int [1:479] 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 ...
## .. ..$ : int [1:479] 14850 14851 14852 14853 14854 14855 14856 14857 14858 14859 ...
## .. ..$ : int [1:479] 15329 15330 15331 15332 15333 15334 15335 15336 15337 15338 ...
## .. ..$ : int [1:479] 15808 15809 15810 15811 15812 15813 15814 15815 15816 15817 ...
## .. ..$ : int [1:479] 16287 16288 16289 16290 16291 16292 16293 16294 16295 16296 ...
## .. ..$ : int [1:479] 16766 16767 16768 16769 16770 16771 16772 16773 16774 16775 ...
## .. ..$ : int [1:479] 17245 17246 17247 17248 17249 17250 17251 17252 17253 17254 ...
## .. ..$ : int [1:479] 17724 17725 17726 17727 17728 17729 17730 17731 17732 17733 ...
## .. ..$ : int [1:479] 18203 18204 18205 18206 18207 18208 18209 18210 18211 18212 ...
## .. ..$ : int [1:479] 18682 18683 18684 18685 18686 18687 18688 18689 18690 18691 ...
## .. ..$ : int [1:479] 19161 19162 19163 19164 19165 19166 19167 19168 19169 19170 ...
## .. ..$ : int [1:479] 19640 19641 19642 19643 19644 19645 19646 19647 19648 19649 ...
## .. ..$ : int [1:479] 20119 20120 20121 20122 20123 20124 20125 20126 20127 20128 ...
## .. ..$ : int [1:479] 20598 20599 20600 20601 20602 20603 20604 20605 20606 20607 ...
## .. ..$ : int [1:479] 21077 21078 21079 21080 21081 21082 21083 21084 21085 21086 ...
## .. ..$ : int [1:479] 21556 21557 21558 21559 21560 21561 21562 21563 21564 21565 ...
## .. ..$ : int [1:479] 22035 22036 22037 22038 22039 22040 22041 22042 22043 22044 ...
## .. ..$ : int [1:479] 22514 22515 22516 22517 22518 22519 22520 22521 22522 22523 ...
## .. ..$ : int [1:479] 22993 22994 22995 22996 22997 22998 22999 23000 23001 23002 ...
## .. ..$ : int [1:479] 23472 23473 23474 23475 23476 23477 23478 23479 23480 23481 ...
## .. ..$ : int [1:479] 23951 23952 23953 23954 23955 23956 23957 23958 23959 23960 ...
## .. ..$ : int [1:479] 24430 24431 24432 24433 24434 24435 24436 24437 24438 24439 ...
## .. ..$ : int [1:479] 24909 24910 24911 24912 24913 24914 24915 24916 24917 24918 ...
## .. ..$ : int [1:479] 25388 25389 25390 25391 25392 25393 25394 25395 25396 25397 ...
## .. ..$ : int [1:479] 25867 25868 25869 25870 25871 25872 25873 25874 25875 25876 ...
## .. ..$ : int [1:479] 26346 26347 26348 26349 26350 26351 26352 26353 26354 26355 ...
## .. ..$ : int [1:479] 26825 26826 26827 26828 26829 26830 26831 26832 26833 26834 ...
## .. ..$ : int [1:479] 27304 27305 27306 27307 27308 27309 27310 27311 27312 27313 ...
## .. ..$ : int [1:479] 27783 27784 27785 27786 27787 27788 27789 27790 27791 27792 ...
## .. ..$ : int [1:479] 28262 28263 28264 28265 28266 28267 28268 28269 28270 28271 ...
## .. ..$ : int [1:479] 28741 28742 28743 28744 28745 28746 28747 28748 28749 28750 ...
## .. ..$ : int [1:479] 29220 29221 29222 29223 29224 29225 29226 29227 29228 29229 ...
## .. ..$ : int [1:479] 29699 29700 29701 29702 29703 29704 29705 29706 29707 29708 ...
## .. ..$ : int [1:479] 30178 30179 30180 30181 30182 30183 30184 30185 30186 30187 ...
## .. ..$ : int [1:479] 30657 30658 30659 30660 30661 30662 30663 30664 30665 30666 ...
## .. ..$ : int [1:479] 31136 31137 31138 31139 31140 31141 31142 31143 31144 31145 ...
## .. ..$ : int [1:479] 31615 31616 31617 31618 31619 31620 31621 31622 31623 31624 ...
## .. ..$ : int [1:479] 32094 32095 32096 32097 32098 32099 32100 32101 32102 32103 ...
## .. ..$ : int [1:479] 32573 32574 32575 32576 32577 32578 32579 32580 32581 32582 ...
## .. ..$ : int [1:479] 33052 33053 33054 33055 33056 33057 33058 33059 33060 33061 ...
## .. ..$ : int [1:479] 33531 33532 33533 33534 33535 33536 33537 33538 33539 33540 ...
## .. ..$ : int [1:479] 34010 34011 34012 34013 34014 34015 34016 34017 34018 34019 ...
## .. ..$ : int [1:479] 34489 34490 34491 34492 34493 34494 34495 34496 34497 34498 ...
## .. ..$ : int [1:479] 34968 34969 34970 34971 34972 34973 34974 34975 34976 34977 ...
## .. ..$ : int [1:479] 35447 35448 35449 35450 35451 35452 35453 35454 35455 35456 ...
## .. ..$ : int [1:479] 35926 35927 35928 35929 35930 35931 35932 35933 35934 35935 ...
## .. ..$ : int [1:479] 36405 36406 36407 36408 36409 36410 36411 36412 36413 36414 ...
## .. ..$ : int [1:479] 36884 36885 36886 36887 36888 36889 36890 36891 36892 36893 ...
## .. ..$ : int [1:479] 37363 37364 37365 37366 37367 37368 37369 37370 37371 37372 ...
## .. ..$ : int [1:479] 37842 37843 37844 37845 37846 37847 37848 37849 37850 37851 ...
## .. ..$ : int [1:479] 38321 38322 38323 38324 38325 38326 38327 38328 38329 38330 ...
## .. ..$ : int [1:479] 38800 38801 38802 38803 38804 38805 38806 38807 38808 38809 ...
## .. ..$ : int [1:479] 39279 39280 39281 39282 39283 39284 39285 39286 39287 39288 ...
## .. ..$ : int [1:479] 39758 39759 39760 39761 39762 39763 39764 39765 39766 39767 ...
## .. ..$ : int [1:479] 40237 40238 40239 40240 40241 40242 40243 40244 40245 40246 ...
## .. ..$ : int [1:479] 40716 40717 40718 40719 40720 40721 40722 40723 40724 40725 ...
## .. ..$ : int [1:479] 41195 41196 41197 41198 41199 41200 41201 41202 41203 41204 ...
## .. ..$ : int [1:479] 41674 41675 41676 41677 41678 41679 41680 41681 41682 41683 ...
## .. ..$ : int [1:479] 42153 42154 42155 42156 42157 42158 42159 42160 42161 42162 ...
## .. ..$ : int [1:479] 42632 42633 42634 42635 42636 42637 42638 42639 42640 42641 ...
## .. ..$ : int [1:479] 43111 43112 43113 43114 43115 43116 43117 43118 43119 43120 ...
## .. ..$ : int [1:479] 43590 43591 43592 43593 43594 43595 43596 43597 43598 43599 ...
## .. ..$ : int [1:479] 44069 44070 44071 44072 44073 44074 44075 44076 44077 44078 ...
## .. ..$ : int [1:479] 44548 44549 44550 44551 44552 44553 44554 44555 44556 44557 ...
## .. ..$ : int [1:479] 45027 45028 45029 45030 45031 45032 45033 45034 45035 45036 ...
## .. ..$ : int [1:479] 45506 45507 45508 45509 45510 45511 45512 45513 45514 45515 ...
## .. ..$ : int [1:479] 45985 45986 45987 45988 45989 45990 45991 45992 45993 45994 ...
## .. ..$ : int [1:479] 46464 46465 46466 46467 46468 46469 46470 46471 46472 46473 ...
## .. ..$ : int [1:479] 46943 46944 46945 46946 46947 46948 46949 46950 46951 46952 ...
## .. .. [list output truncated]
## .. ..@ ptype: int(0)
## ..- attr(*, ".drop")= logi TRUE
country$date <- country$date %>% sub("X", "", .) %>% as.Date("%m.%d.%y")
str(country) # check date Date
## grouped_df[,5] [91,968 × 5] (S3: grouped_df/tbl_df/tbl/data.frame)
## $ Country.Region: chr [1:91968] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
## $ date : Date[1:91968], format: "2021-01-01" "2021-01-10" ...
## $ confirmed : int [1:91968] 51526 53489 53538 53584 53584 53775 53831 53938 53984 54062 ...
## $ deaths : int [1:91968] 2191 2277 2288 2301 2301 2314 2324 2336 2339 2343 ...
## $ recovered : int [1:91968] 41727 43948 44137 44608 44850 45298 45434 45465 45868 46359 ...
## - attr(*, "groups")= tibble[,2] [192 × 2] (S3: tbl_df/tbl/data.frame)
## ..$ Country.Region: chr [1:192] "Afghanistan" "Albania" "Algeria" "Andorra" ...
## ..$ .rows : list<int> [1:192]
## .. ..$ : int [1:479] 1 2 3 4 5 6 7 8 9 10 ...
## .. ..$ : int [1:479] 480 481 482 483 484 485 486 487 488 489 ...
## .. ..$ : int [1:479] 959 960 961 962 963 964 965 966 967 968 ...
## .. ..$ : int [1:479] 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 ...
## .. ..$ : int [1:479] 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 ...
## .. ..$ : int [1:479] 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 ...
## .. ..$ : int [1:479] 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 ...
## .. ..$ : int [1:479] 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 ...
## .. ..$ : int [1:479] 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 ...
## .. ..$ : int [1:479] 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 ...
## .. ..$ : int [1:479] 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 ...
## .. ..$ : int [1:479] 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 ...
## .. ..$ : int [1:479] 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 ...
## .. ..$ : int [1:479] 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 ...
## .. ..$ : int [1:479] 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 ...
## .. ..$ : int [1:479] 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 ...
## .. ..$ : int [1:479] 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 ...
## .. ..$ : int [1:479] 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 ...
## .. ..$ : int [1:479] 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 ...
## .. ..$ : int [1:479] 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 ...
## .. ..$ : int [1:479] 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 ...
## .. ..$ : int [1:479] 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 ...
## .. ..$ : int [1:479] 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 ...
## .. ..$ : int [1:479] 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 ...
## .. ..$ : int [1:479] 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 ...
## .. ..$ : int [1:479] 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 ...
## .. ..$ : int [1:479] 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 ...
## .. ..$ : int [1:479] 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 ...
## .. ..$ : int [1:479] 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 ...
## .. ..$ : int [1:479] 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 ...
## .. ..$ : int [1:479] 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 ...
## .. ..$ : int [1:479] 14850 14851 14852 14853 14854 14855 14856 14857 14858 14859 ...
## .. ..$ : int [1:479] 15329 15330 15331 15332 15333 15334 15335 15336 15337 15338 ...
## .. ..$ : int [1:479] 15808 15809 15810 15811 15812 15813 15814 15815 15816 15817 ...
## .. ..$ : int [1:479] 16287 16288 16289 16290 16291 16292 16293 16294 16295 16296 ...
## .. ..$ : int [1:479] 16766 16767 16768 16769 16770 16771 16772 16773 16774 16775 ...
## .. ..$ : int [1:479] 17245 17246 17247 17248 17249 17250 17251 17252 17253 17254 ...
## .. ..$ : int [1:479] 17724 17725 17726 17727 17728 17729 17730 17731 17732 17733 ...
## .. ..$ : int [1:479] 18203 18204 18205 18206 18207 18208 18209 18210 18211 18212 ...
## .. ..$ : int [1:479] 18682 18683 18684 18685 18686 18687 18688 18689 18690 18691 ...
## .. ..$ : int [1:479] 19161 19162 19163 19164 19165 19166 19167 19168 19169 19170 ...
## .. ..$ : int [1:479] 19640 19641 19642 19643 19644 19645 19646 19647 19648 19649 ...
## .. ..$ : int [1:479] 20119 20120 20121 20122 20123 20124 20125 20126 20127 20128 ...
## .. ..$ : int [1:479] 20598 20599 20600 20601 20602 20603 20604 20605 20606 20607 ...
## .. ..$ : int [1:479] 21077 21078 21079 21080 21081 21082 21083 21084 21085 21086 ...
## .. ..$ : int [1:479] 21556 21557 21558 21559 21560 21561 21562 21563 21564 21565 ...
## .. ..$ : int [1:479] 22035 22036 22037 22038 22039 22040 22041 22042 22043 22044 ...
## .. ..$ : int [1:479] 22514 22515 22516 22517 22518 22519 22520 22521 22522 22523 ...
## .. ..$ : int [1:479] 22993 22994 22995 22996 22997 22998 22999 23000 23001 23002 ...
## .. ..$ : int [1:479] 23472 23473 23474 23475 23476 23477 23478 23479 23480 23481 ...
## .. ..$ : int [1:479] 23951 23952 23953 23954 23955 23956 23957 23958 23959 23960 ...
## .. ..$ : int [1:479] 24430 24431 24432 24433 24434 24435 24436 24437 24438 24439 ...
## .. ..$ : int [1:479] 24909 24910 24911 24912 24913 24914 24915 24916 24917 24918 ...
## .. ..$ : int [1:479] 25388 25389 25390 25391 25392 25393 25394 25395 25396 25397 ...
## .. ..$ : int [1:479] 25867 25868 25869 25870 25871 25872 25873 25874 25875 25876 ...
## .. ..$ : int [1:479] 26346 26347 26348 26349 26350 26351 26352 26353 26354 26355 ...
## .. ..$ : int [1:479] 26825 26826 26827 26828 26829 26830 26831 26832 26833 26834 ...
## .. ..$ : int [1:479] 27304 27305 27306 27307 27308 27309 27310 27311 27312 27313 ...
## .. ..$ : int [1:479] 27783 27784 27785 27786 27787 27788 27789 27790 27791 27792 ...
## .. ..$ : int [1:479] 28262 28263 28264 28265 28266 28267 28268 28269 28270 28271 ...
## .. ..$ : int [1:479] 28741 28742 28743 28744 28745 28746 28747 28748 28749 28750 ...
## .. ..$ : int [1:479] 29220 29221 29222 29223 29224 29225 29226 29227 29228 29229 ...
## .. ..$ : int [1:479] 29699 29700 29701 29702 29703 29704 29705 29706 29707 29708 ...
## .. ..$ : int [1:479] 30178 30179 30180 30181 30182 30183 30184 30185 30186 30187 ...
## .. ..$ : int [1:479] 30657 30658 30659 30660 30661 30662 30663 30664 30665 30666 ...
## .. ..$ : int [1:479] 31136 31137 31138 31139 31140 31141 31142 31143 31144 31145 ...
## .. ..$ : int [1:479] 31615 31616 31617 31618 31619 31620 31621 31622 31623 31624 ...
## .. ..$ : int [1:479] 32094 32095 32096 32097 32098 32099 32100 32101 32102 32103 ...
## .. ..$ : int [1:479] 32573 32574 32575 32576 32577 32578 32579 32580 32581 32582 ...
## .. ..$ : int [1:479] 33052 33053 33054 33055 33056 33057 33058 33059 33060 33061 ...
## .. ..$ : int [1:479] 33531 33532 33533 33534 33535 33536 33537 33538 33539 33540 ...
## .. ..$ : int [1:479] 34010 34011 34012 34013 34014 34015 34016 34017 34018 34019 ...
## .. ..$ : int [1:479] 34489 34490 34491 34492 34493 34494 34495 34496 34497 34498 ...
## .. ..$ : int [1:479] 34968 34969 34970 34971 34972 34973 34974 34975 34976 34977 ...
## .. ..$ : int [1:479] 35447 35448 35449 35450 35451 35452 35453 35454 35455 35456 ...
## .. ..$ : int [1:479] 35926 35927 35928 35929 35930 35931 35932 35933 35934 35935 ...
## .. ..$ : int [1:479] 36405 36406 36407 36408 36409 36410 36411 36412 36413 36414 ...
## .. ..$ : int [1:479] 36884 36885 36886 36887 36888 36889 36890 36891 36892 36893 ...
## .. ..$ : int [1:479] 37363 37364 37365 37366 37367 37368 37369 37370 37371 37372 ...
## .. ..$ : int [1:479] 37842 37843 37844 37845 37846 37847 37848 37849 37850 37851 ...
## .. ..$ : int [1:479] 38321 38322 38323 38324 38325 38326 38327 38328 38329 38330 ...
## .. ..$ : int [1:479] 38800 38801 38802 38803 38804 38805 38806 38807 38808 38809 ...
## .. ..$ : int [1:479] 39279 39280 39281 39282 39283 39284 39285 39286 39287 39288 ...
## .. ..$ : int [1:479] 39758 39759 39760 39761 39762 39763 39764 39765 39766 39767 ...
## .. ..$ : int [1:479] 40237 40238 40239 40240 40241 40242 40243 40244 40245 40246 ...
## .. ..$ : int [1:479] 40716 40717 40718 40719 40720 40721 40722 40723 40724 40725 ...
## .. ..$ : int [1:479] 41195 41196 41197 41198 41199 41200 41201 41202 41203 41204 ...
## .. ..$ : int [1:479] 41674 41675 41676 41677 41678 41679 41680 41681 41682 41683 ...
## .. ..$ : int [1:479] 42153 42154 42155 42156 42157 42158 42159 42160 42161 42162 ...
## .. ..$ : int [1:479] 42632 42633 42634 42635 42636 42637 42638 42639 42640 42641 ...
## .. ..$ : int [1:479] 43111 43112 43113 43114 43115 43116 43117 43118 43119 43120 ...
## .. ..$ : int [1:479] 43590 43591 43592 43593 43594 43595 43596 43597 43598 43599 ...
## .. ..$ : int [1:479] 44069 44070 44071 44072 44073 44074 44075 44076 44077 44078 ...
## .. ..$ : int [1:479] 44548 44549 44550 44551 44552 44553 44554 44555 44556 44557 ...
## .. ..$ : int [1:479] 45027 45028 45029 45030 45031 45032 45033 45034 45035 45036 ...
## .. ..$ : int [1:479] 45506 45507 45508 45509 45510 45511 45512 45513 45514 45515 ...
## .. ..$ : int [1:479] 45985 45986 45987 45988 45989 45990 45991 45992 45993 45994 ...
## .. ..$ : int [1:479] 46464 46465 46466 46467 46468 46469 46470 46471 46472 46473 ...
## .. ..$ : int [1:479] 46943 46944 46945 46946 46947 46948 46949 46950 46951 46952 ...
## .. .. [list output truncated]
## .. ..@ ptype: int(0)
## ..- attr(*, ".drop")= logi TRUE
# Create new variable: number of days
country <- country %>% group_by(Country.Region) %>% mutate(cumconfirmed=cumsum(confirmed), days = date - first(date) + 1)
## Warning in mask$eval_all_mutate(quo): integer overflow in 'cumsum'; use
## 'cumsum(as.numeric(.))'
## Warning in mask$eval_all_mutate(quo): integer overflow in 'cumsum'; use
## 'cumsum(as.numeric(.))'
## Warning in mask$eval_all_mutate(quo): integer overflow in 'cumsum'; use
## 'cumsum(as.numeric(.))'
AGGREGATE AT WORLD, ITALY, SOUTH AFRICA AND GUINEA LEVEL-
# Aggregate at world level
#world <- country %>% group_by(date) %>% summarize(confirmed=sum(confirmed), cumconfirmed=sum(cumconfirmed), deaths=sum(deaths), recovered=sum(recovered)) %>% mutate(days = date - first(date) + 1)
world <- country %>% group_by(date) %>% summarize(confirmed=sum(confirmed), deaths=sum(deaths), recovered=sum(recovered)) %>% mutate(days = date - first(date) + 1)
# Extract specific country: Italy
italy <- country %>% filter(Country.Region=="Italy")
# Extract specific country: South Africa
south_africa <- country %>% filter(Country.Region=="South Africa")
# Extract specific country: Guinea
guinea <- country %>% filter(Country.Region=="Guinea")
SUMMARY STATISTICS
# SUMMARY STATISTICS
summary(italy)
## Country.Region date confirmed deaths
## Length:479 Min. :2020-01-22 Min. : 0 Min. : 0
## Class :character 1st Qu.:2020-05-20 1st Qu.: 227685 1st Qu.: 32408
## Mode :character Median :2020-09-17 Median : 293025 Median : 35658
## Mean :2020-09-17 Mean :1198157 Mean : 50365
## 3rd Qu.:2021-01-14 3rd Qu.:2344351 3rd Qu.: 81086
## Max. :2021-05-14 Max. :4146722 Max. :123927
## recovered cumconfirmed days
## Min. : 0 Min. : 2129376 Length:479
## 1st Qu.: 133421 1st Qu.:156371520 Class :difftime
## Median : 215954 Median :340269461 Mode :numeric
## Mean : 900218 Mean :333029182
## 3rd Qu.:1703540 3rd Qu.:543159172
## Max. :3683189 Max. :573917101
summary(south_africa)
## Country.Region date confirmed deaths
## Length:479 Min. :2020-01-22 Min. : 0 Min. : 0
## Class :character 1st Qu.:2020-05-20 1st Qu.: 18570 1st Qu.: 354
## Mode :character Median :2020-09-17 Median : 655572 Median :15772
## Mean :2020-09-17 Mean : 671094 Mean :19653
## 3rd Qu.:2021-01-14 3rd Qu.:1304246 3rd Qu.:36160
## Max. :2021-05-14 Max. :1608393 Max. :55124
## recovered cumconfirmed days
## Min. : 0 Min. : 1073887 Length:479
## 1st Qu.: 8950 1st Qu.:101089680 Class :difftime
## Median : 585303 Median :192492584 Mode :numeric
## Mean : 599118 Mean :181364204
## 3rd Qu.:1056215 3rd Qu.:271553311
## Max. :1522165 Max. :321454258
summary(guinea)
## Country.Region date confirmed deaths
## Length:479 Min. :2020-01-22 Min. : 0 Min. : 0.00
## Class :character 1st Qu.:2020-05-20 1st Qu.: 2965 1st Qu.: 18.00
## Mode :character Median :2020-09-17 Median :10154 Median : 63.00
## Mean :2020-09-17 Mean : 9429 Mean : 56.84
## 3rd Qu.:2021-01-14 3rd Qu.:14058 3rd Qu.: 81.00
## Max. :2021-05-14 Max. :22746 Max. :151.00
## recovered cumconfirmed days
## Min. : 0 Min. : 13738 Length:479
## 1st Qu.: 1550 1st Qu.:1416859 Class :difftime
## Median : 9612 Median :2466079 Mode :numeric
## Mean : 8391 Mean :2423135
## 3rd Qu.:13310 3rd Qu.:3626142
## Max. :20366 Max. :4516309
BAR CHART CONFIRMED CASES AT WORLD LEVEL
# GRAPHS
# Barchart of cases over time at world level
library(ggplot2)
# World confirmed
ggplot(world, aes(x=date, y=confirmed)) + geom_bar(stat="identity", width=0.5) +
theme_classic() +
labs(title = "Covid-19 Global Confirmed Cases", x= "Date", y= "Daily confirmed cases") +
theme(plot.title = element_text(hjust = 0.5))
COMBINING (CONFIRMED, RECOVERED, DEATHS) LINE CHART
# GRAPHS
# Line Chart
# world, confirmed, recovered, deaths
library(ggplot2)
# World confirmed
g=ggplot(world, aes(date))
g=g+geom_line(aes(y=confirmed), colour='yellow', size=1.5)
g=g+geom_line(aes(y=recovered), colour='green', size=1.5)
g=g+geom_line(aes(y=deaths), colour='red', size=1.5)
g+ggtitle('Combined cumative confirmed, recovred, and deaths cases')+ylab('Values')+xlab('date')
BAR CHART CONFIRMED CASES AT ITALY LEVEL
# Italy confirmed cases over time
ggplot(italy, aes(x=date, y=confirmed)) + geom_bar(stat="identity", width=0.5) +
theme_classic() +
labs(title = "Covid-19 Confirmed Cases in Italy", x= "Date", y= "Daily confirmed cases") +
theme(plot.title = element_text(hjust = 0.5))
BAR CHART CONFIRMED CASES AT SOUTH AFRICA LEVEL
# South Africa confirmed
ggplot(south_africa, aes(x=date, y=confirmed)) + geom_bar(stat="identity", width=0.5) +
theme_classic() +
labs(title = "Covid-19 Confirmed Cases in South Africa", x= "Date", y= "Daily confirmed cases") +
theme(plot.title = element_text(hjust = 0.5))
BAR CHART CONFIRMED CASES AT GUINEA LEVEL
# Guinea confirmed
ggplot(guinea, aes(x=date, y=confirmed)) + geom_bar(stat="identity", width=0.5) +
theme_classic() +
labs(title = "Covid-19 Confirmed Cases in Guinea", x= "Date", y= "Daily confirmed cases") +
theme(plot.title = element_text(hjust = 0.5))
WORLD CONFIRMED, DEATH, AND RECOVERED- (AREA CHART)
# World confirmed, deaths and recovered
str(world)
## tibble[,5] [479 × 5] (S3: tbl_df/tbl/data.frame)
## $ date : Date[1:479], format: "2020-01-22" "2020-01-23" ...
## $ confirmed: int [1:479] 557 655 941 1433 2118 2927 5578 6167 8235 9927 ...
## $ deaths : int [1:479] 17 18 26 42 56 82 131 133 171 213 ...
## $ recovered: int [1:479] 30 32 39 42 56 65 108 127 145 225 ...
## $ days : 'difftime' num [1:479] 1 2 3 4 ...
## ..- attr(*, "units")= chr "days"
world %>% gather("Type", "Cases", -c(date, days)) %>%
ggplot(aes(x=date, y=Cases, colour=Type)) + geom_bar(stat="identity", width=0.2, fill="white") +
theme_classic() +
labs(title = "Covid-19 Global Cases", x= "Date", y= "Daily cases") +
theme(plot.title = element_text(hjust = 0.5))
WORLD CONFIRMED WITH COUNT IN LOG10 SCALE
# World confirmed with counts in log10 scale
ggplot(world, aes(x=days, y=confirmed)) + geom_line() +
theme_classic() +
labs(title = "Covid-19 Global Confirmed Cases", x= "Days", y= "Daily confirmed cases (log scale)") +
theme(plot.title = element_text(hjust = 0.5)) +
scale_y_continuous(trans="log10")
## Don't know how to automatically pick scale for object of type difftime. Defaulting to continuous.
WORLD CONFIRMED, DEATH AND RECOVERED CASES (LINE CHART)
str(world)
## tibble[,5] [479 × 5] (S3: tbl_df/tbl/data.frame)
## $ date : Date[1:479], format: "2020-01-22" "2020-01-23" ...
## $ confirmed: int [1:479] 557 655 941 1433 2118 2927 5578 6167 8235 9927 ...
## $ deaths : int [1:479] 17 18 26 42 56 82 131 133 171 213 ...
## $ recovered: int [1:479] 30 32 39 42 56 65 108 127 145 225 ...
## $ days : 'difftime' num [1:479] 1 2 3 4 ...
## ..- attr(*, "units")= chr "days"
world %>% gather("Type", "Cases", -c(date, days)) %>%
ggplot(aes(x=days, y=Cases, colour=Type)) + geom_line() +
theme_classic() +
labs(title = "Covid-19 Global Cases", x= "Days", y= "Daily cases") +
theme(plot.title = element_text(hjust = 0.5))
## Don't know how to automatically pick scale for object of type difftime. Defaulting to continuous.
COMPARING 3 COUNTRIES (ITALY, SOUTH AFRICA AND GUINEA)
# Confirmed by country for select countries with counts in log10 scale
countryselection <- country %>% filter(Country.Region==c("Italy", "South Africa", "Guinea"))
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
## Warning in Country.Region == c("Italy", "South Africa", "Guinea"): longer object
## length is not a multiple of shorter object length
ggplot(countryselection, aes(x=days, y=confirmed, colour=Country.Region)) + geom_line(size=1) +
theme_classic() +
labs(title = "Covid-19 Confirmed Cases by Country", x= "Days", y= "Daily confirmed cases (log scale)") +
theme(plot.title = element_text(hjust = 0.5)) +
scale_y_continuous(trans="log10")
## Don't know how to automatically pick scale for object of type difftime. Defaulting to continuous.
## Warning: Transformation introduced infinite values in continuous y-axis
PIE CHART (ITALY, SOUTH AFRICA, GUINEA)-
bp=ggplot(countryselection, aes(x='', y=confirmed, fill=Country.Region))+geom_bar( stat='identity')
bp
pie=bp+coord_polar('y', start = 0)
pie
MATRIX LINE (CONFIRMED, RECOVERED, DEATH)- ITALY, SOUTH AFRICA, AND GUINEA
# Matrix of line graphs of confirmed, deaths and recovered for select countries in log10 scale
str(countryselection)
## grouped_df[,7] [479 × 7] (S3: grouped_df/tbl_df/tbl/data.frame)
## $ Country.Region: chr [1:479] "Guinea" "Guinea" "Guinea" "Guinea" ...
## $ date : Date[1:479], format: "2021-01-11" "2021-01-14" ...
## $ confirmed : int [1:479] 13980 14051 14114 13784 0 14300 0 14379 0 14451 ...
## $ deaths : int [1:479] 81 81 81 81 0 81 0 82 0 82 ...
## $ recovered : int [1:479] 13233 13301 13338 13153 0 13632 0 13798 0 13999 ...
## $ cumconfirmed : int [1:479] 41660 83787 126064 168220 196663 225225 239544 268298 282733 311619 ...
## $ days : 'difftime' num [1:479] 11 14 17 2 ...
## ..- attr(*, "units")= chr "days"
## - attr(*, "groups")= tibble[,2] [3 × 2] (S3: tbl_df/tbl/data.frame)
## ..$ Country.Region: chr [1:3] "Guinea" "Italy" "South Africa"
## ..$ .rows : list<int> [1:3]
## .. ..$ : int [1:159] 1 2 3 4 5 6 7 8 9 10 ...
## .. ..$ : int [1:160] 160 161 162 163 164 165 166 167 168 169 ...
## .. ..$ : int [1:160] 320 321 322 323 324 325 326 327 328 329 ...
## .. ..@ ptype: int(0)
## ..- attr(*, ".drop")= logi TRUE
countryselection %>% gather("Type", "Cases", -c(date, days, Country.Region)) %>%
ggplot(aes(x=days, y=Cases, colour=Country.Region)) + geom_line(size=1) +
theme_classic() +
labs(title = "Covid-19 Cases by Country", x= "Days", y= "Daily cases (log scale)") +
theme(plot.title = element_text(hjust = 0.5)) +
scale_y_continuous(trans="log10") +
facet_grid(rows=vars(Type))
## Don't know how to automatically pick scale for object of type difftime. Defaulting to continuous.
## Warning: Transformation introduced infinite values in continuous y-axis
MAPPING
## Map
countrytotal <- country %>% group_by(Country.Region) %>% summarize(cumconfirmed=sum(confirmed), cumdeaths=sum(deaths), cumrecovered=sum(recovered))
# Basemap from package tmap
library(tmap)
data(World)
class(World)
## [1] "sf" "data.frame"
# Combine basemap data to covid data
countrytotal$Country.Region[!countrytotal$Country.Region %in% World$name]
## [1] "Andorra" "Antigua and Barbuda"
## [3] "Bahrain" "Barbados"
## [5] "Bosnia and Herzegovina" "Burma"
## [7] "Cabo Verde" "Central African Republic"
## [9] "Comoros" "Congo (Brazzaville)"
## [11] "Congo (Kinshasa)" "Czechia"
## [13] "Diamond Princess" "Dominica"
## [15] "Dominican Republic" "Equatorial Guinea"
## [17] "Eswatini" "Grenada"
## [19] "Holy See" "Korea, South"
## [21] "Laos" "Liechtenstein"
## [23] "Maldives" "Malta"
## [25] "Marshall Islands" "Mauritius"
## [27] "Micronesia" "Monaco"
## [29] "MS Zaandam" "North Macedonia"
## [31] "Saint Kitts and Nevis" "Saint Lucia"
## [33] "Saint Vincent and the Grenadines" "Samoa"
## [35] "San Marino" "Sao Tome and Principe"
## [37] "Seychelles" "Singapore"
## [39] "Solomon Islands" "South Sudan"
## [41] "Taiwan*" "US"
## [43] "West Bank and Gaza"
list <- which(!countrytotal$Country.Region %in% World$name)
countrytotal$country <- as.character(countrytotal$Country.Region)
countrytotal$country[list] <-
c("Andorra", "Antigua and Barbuda", "Bahrain",
"Barbados", "Bosnia and Herz.", "Myanmar",
"Cape Verde", "Central African Rep.", "Congo",
"Dem. Rep. Congo", "Czech Rep.", "Diamond Princess",
"Dominica", "Dominican Rep.", "Eq. Guinea",
"Swaziland", "Grenada", "Holy See",
"Korea", "Lao PDR", "Liechtenstein",
"Maldives", "Malta", "Mauritius",
"Monaco", "MS Zaandam", "Macedonia",
"Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines",
"San Marino", "Sao Tome and Principe", "Seychelles",
"Singapore", "S. Sudan", "Taiwan",
"United States", "Palestine", "W. Sahara")
## Warning in countrytotal$country[list] <- c("Andorra", "Antigua and Barbuda", :
## number of items to replace is not a multiple of replacement length
countrytotal$Country.Region[!countrytotal$country %in% World$name]
## [1] "Andorra" "Antigua and Barbuda"
## [3] "Bahrain" "Barbados"
## [5] "Cabo Verde" "Czechia"
## [7] "Diamond Princess" "Eswatini"
## [9] "Grenada" "Laos"
## [11] "Liechtenstein" "Maldives"
## [13] "Malta" "Marshall Islands"
## [15] "Mauritius" "Monaco"
## [17] "MS Zaandam" "North Macedonia"
## [19] "Saint Kitts and Nevis" "Saint Lucia"
## [21] "Saint Vincent and the Grenadines" "Samoa"
## [23] "South Sudan" "Taiwan*"
## [25] "US" "West Bank and Gaza"
World$country <- World$name
worldmap <- left_join(World, countrytotal, by="country")
worldmap$cumconfirmed[is.na(worldmap$cumconfirmed)] <- 0
# Map
ggplot(data = worldmap) + geom_sf(aes(fill=cumconfirmed), color="black") +
ggtitle("World Map of Confirmed Covid Cases") + theme_bw()
GLOBAL COVID CONFIRMED CASES MAP
# Number of cases
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble 3.1.1 ✓ stringr 1.4.0
## ✓ purrr 0.3.4 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
library(readr)
library(maps)
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
library(viridis)
## Loading required package: viridisLite
## get the COVID-19 data
confirmed_cases <- 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")
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## .default = col_double(),
## `Province/State` = col_character(),
## `Country/Region` = col_character()
## )
## ℹ Use `spec()` for the full column specifications.
## get the world map
world <- map_data("world")
# cutoffs based on the number of cases
mybreaks <- c(1, 20, 100, 1000, 50000)
ggplot() +
geom_polygon(data = world, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) +
geom_point(data=confirmed_cases, aes(x=Long, y=Lat, size=`3/3/20`, color=`3/3/20`),stroke=F, alpha=0.7) +
scale_size_continuous(name="Cases", trans="log", range=c(1,7),breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-49,999", "50,000+")) +
scale_alpha_continuous(name="Cases", trans="log", range=c(0.1, 0.9),breaks=mybreaks) +
scale_color_viridis_c(option="inferno",name="Cases", trans="log",breaks=mybreaks, labels = c("1-19", "20-99", "100-999", "1,000-49,999", "50,000+")) +
theme_void() +
guides( colour = guide_legend()) +
labs(caption = "Data Repository provided by Johns Hopkins CSSE") +
theme(
legend.position = "bottom",
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA)
)+ggtitle("World Map of Confirmed Covid Cases") + theme_bw()
## Warning: Transformation introduced infinite values in discrete y-axis
## Warning: Transformation introduced infinite values in discrete y-axis
## Warning in sqrt(x): NaNs produced
## Warning: Removed 159 rows containing missing values (geom_point).