Use coronavirus
package to obtain data
install.packages("coronavirus")
library(coronavirus)
Load data
data(coronavirus)
Data description
head(coronavirus)
date province country lat long type cases
1 2020-01-22 Afghanistan 33.93911 67.70995 confirmed 0
2 2020-01-22 Albania 41.15330 20.16830 confirmed 0
3 2020-01-22 Algeria 28.03390 1.65960 confirmed 0
4 2020-01-22 Andorra 42.50630 1.52180 confirmed 0
5 2020-01-22 Angola -11.20270 17.87390 confirmed 0
6 2020-01-22 Antigua and Barbuda 17.06080 -61.79640 confirmed 0
tail(coronavirus)
date province country lat long type
399991 2021-05-27 Venezuela 6.42380 -66.58970 recovered
399992 2021-05-27 Vietnam 14.05832 108.27720 recovered
399993 2021-05-27 West Bank and Gaza 31.95220 35.23320 recovered
399994 2021-05-27 Yemen 15.55273 48.51639 recovered
399995 2021-05-27 Zambia -13.13390 27.84933 recovered
399996 2021-05-27 Zimbabwe -19.01544 29.15486 recovered
cases
399991 853
399992 0
399993 0
399994 33
399995 82
399996 10
To use help file
?coronavirus
Find the country name from the list below
unique(coronavirus$country)
[1] "Afghanistan" "Albania"
[3] "Algeria" "Andorra"
[5] "Angola" "Antigua and Barbuda"
[7] "Argentina" "Armenia"
[9] "Australia" "Austria"
[11] "Azerbaijan" "Bahamas"
[13] "Bahrain" "Bangladesh"
[15] "Barbados" "Belarus"
[17] "Belgium" "Belize"
[19] "Benin" "Bhutan"
[21] "Bolivia" "Bosnia and Herzegovina"
[23] "Botswana" "Brazil"
[25] "Brunei" "Bulgaria"
[27] "Burkina Faso" "Burma"
[29] "Burundi" "Cabo Verde"
[31] "Cambodia" "Cameroon"
[33] "Canada" "Central African Republic"
[35] "Chad" "Chile"
[37] "China" "Colombia"
[39] "Comoros" "Congo (Brazzaville)"
[41] "Congo (Kinshasa)" "Costa Rica"
[43] "Cote d'Ivoire" "Croatia"
[45] "Cuba" "Cyprus"
[47] "Czechia" "Denmark"
[49] "Diamond Princess" "Djibouti"
[51] "Dominica" "Dominican Republic"
[53] "Ecuador" "Egypt"
[55] "El Salvador" "Equatorial Guinea"
[57] "Eritrea" "Estonia"
[59] "Eswatini" "Ethiopia"
[61] "Fiji" "Finland"
[63] "France" "Gabon"
[65] "Gambia" "Georgia"
[67] "Germany" "Ghana"
[69] "Greece" "Grenada"
[71] "Guatemala" "Guinea"
[73] "Guinea-Bissau" "Guyana"
[75] "Haiti" "Holy See"
[77] "Honduras" "Hungary"
[79] "Iceland" "India"
[81] "Indonesia" "Iran"
[83] "Iraq" "Ireland"
[85] "Israel" "Italy"
[87] "Jamaica" "Japan"
[89] "Jordan" "Kazakhstan"
[91] "Kenya" "Kiribati"
[93] "Korea, South" "Kosovo"
[95] "Kuwait" "Kyrgyzstan"
[97] "Laos" "Latvia"
[99] "Lebanon" "Lesotho"
[101] "Liberia" "Libya"
[103] "Liechtenstein" "Lithuania"
[105] "Luxembourg" "MS Zaandam"
[107] "Madagascar" "Malawi"
[109] "Malaysia" "Maldives"
[111] "Mali" "Malta"
[113] "Marshall Islands" "Mauritania"
[115] "Mauritius" "Mexico"
[117] "Micronesia" "Moldova"
[119] "Monaco" "Mongolia"
[121] "Montenegro" "Morocco"
[123] "Mozambique" "Namibia"
[125] "Nepal" "Netherlands"
[127] "New Zealand" "Nicaragua"
[129] "Niger" "Nigeria"
[131] "North Macedonia" "Norway"
[133] "Oman" "Pakistan"
[135] "Panama" "Papua New Guinea"
[137] "Paraguay" "Peru"
[139] "Philippines" "Poland"
[141] "Portugal" "Qatar"
[143] "Romania" "Russia"
[145] "Rwanda" "Saint Kitts and Nevis"
[147] "Saint Lucia" "Saint Vincent and the Grenadines"
[149] "Samoa" "San Marino"
[151] "Sao Tome and Principe" "Saudi Arabia"
[153] "Senegal" "Serbia"
[155] "Seychelles" "Sierra Leone"
[157] "Singapore" "Slovakia"
[159] "Slovenia" "Solomon Islands"
[161] "Somalia" "South Africa"
[163] "South Sudan" "Spain"
[165] "Sri Lanka" "Sudan"
[167] "Suriname" "Sweden"
[169] "Switzerland" "Syria"
[171] "Taiwan*" "Tajikistan"
[173] "Tanzania" "Thailand"
[175] "Timor-Leste" "Togo"
[177] "Trinidad and Tobago" "Tunisia"
[179] "Turkey" "US"
[181] "Uganda" "Ukraine"
[183] "United Arab Emirates" "United Kingdom"
[185] "Uruguay" "Uzbekistan"
[187] "Vanuatu" "Venezuela"
[189] "Vietnam" "West Bank and Gaza"
[191] "Yemen" "Zambia"
[193] "Zimbabwe"
Useful codes: Data Analysis for the USA
- Load necessary packages
library(tidyverse)
library(magrittr)
- Filter USA
usa_corona <- coronavirus %>% filter(country == "US")
- Extract recovered cases in the USA
recover_usa_corona <- usa_corona %>% filter(type=="confirmed")
head(recover_usa_corona)
date province country lat long type cases
1 2020-01-22 US 40 -100 confirmed 1
2 2020-01-23 US 40 -100 confirmed 0
3 2020-01-24 US 40 -100 confirmed 1
4 2020-01-25 US 40 -100 confirmed 0
5 2020-01-26 US 40 -100 confirmed 3
6 2020-01-27 US 40 -100 confirmed 0
ggplot(recover_usa_corona, aes(x=date, y=cases)) + geom_line() + ggtitle("US: Daily Covid-19 Recoveries")
- Plot country
library(ggplot2)
library(maptools)
library(tibble)
library(tidyverse)
library(ggrepel)
library(png)
library(grid)
library(sp)
data(wrld_simpl)
p <- ggplot() +
geom_polygon(
data = wrld_simpl,
aes(x = long, y = lat, group = group), fill = "gray", colour = "white"
) +
coord_cartesian(xlim = c(-180, 180), ylim = c(-90, 90)) +
scale_x_continuous(breaks = seq(-180, 180, 120)) +
scale_y_continuous(breaks = seq(-90, 90, 100))
p +
geom_point(
data = usa_corona, aes(x = long, y = lat), color = "red", size
= 1
)