# install the ncov2019 package remotes::install_github("GuangchuangYu/nCov2019") # open it in the library library(nCov2019) # get ncov data x <- get_nCov2019(lang='en') # check the total confirmed cases and update date x # see a table of global values x['global', ] # Check values within china x[] # check table of values in decending order x[1,] # Check data from one province x['Hubei', ] # replace Hubei with any province install.packages("forcats") library(forcats) install.packages("ggplot2") library(ggplot2) # make your first plot of the data d = x['Anhui',] # replace Anhui with any province d$confirm=as.numeric(d$confirm) d$name = fct_reorder(d$name, d$confirm) ggplot(d, aes(name, confirm)) + geom_col(fill='firebrick', alpha = 05) + coord_flip() + geom_text(aes(y = confirm+2, label=confirm), hjust=0) + theme_minimal(base_size=14) + scale_y_continuous(expand=c(0,10)) + xlab(NULL) + ylab(NULL) # check values for the current day head(x[by='today'], 10) # get a total summary summary(x) # summarize by the day summary(x, by="today") library(ggplot2) ggplot(summary(x), aes(as.Date(date, "%m.%d"), as.numeric(confirm))) + geom_col(fill='firebrick') + theme_minimal(base_size = 14) + xlab(NULL) + ylab(NULL) + labs(caption = paste("accessed date:", time(x))) x <- load_nCov2019(lang='en') x # only check the first 6 rows head(x[][c(1:6, 9:11)]) # check the first 6 rows for Wuhan head(subset(x['Hubei',], city == "Wuhan"))[c(1:6, 9:11)] library(ggplot2) install.packages("ggrepel") require(ggrepel) # See the cumulative rate of confirmed cases over time d <- x['Anhui',] # replace Anhui with any province ggplot(d, aes(time, as.numeric(cum_confirm), group=city, color=city)) + geom_point() + geom_line() + geom_text_repel(aes(label=city), data=d[d$time == time(x), ], hjust=1) + theme_minimal(base_size = 14) + theme(legend.position='none') + scale_color_viridis_d()+ xlab(NULL) + ylab(NULL) # read the summary of cumulative cases head(summary(x)[,1:5]) # summarize from a specific province summary(x, 'Hubei')[,1:5] # city-specific cumulative summary ggplot(subset(x['Hubei',], city == "Huanggang"), aes(time, as.numeric(cum_confirm))) + geom_col(fill = "firebrick")+ theme_classic() require(nCov2019) x = get_nCov2019(lang='en') # plot affected areas on a world map plot(x) # install a china map remotes::install_github("GuangchuangYu/chinamap", force = TRUE) require(chinamap) cn = get_map_china() ## translate province cn$province <- trans_province(cn$province) # plot a chloropleth map of affected areas plot(x, chinamap=cn) # change the color plot(x, chinamap=cn, palette="Purples")