Loading data
# Packages
#library(easypackages)
#packages("readxl", "httr", "tidyverse", "ggplot2", "ggthemes", "Rcpp")
#library(rgeos) #Musi byt spusteny pred maptools (nahrazuje gpclib)
#library(ggmap)
#library(maptools)
#library(rgdal)
#library(RColorBrewer)
#library(plotly)
#browseURL("https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide", browser = getOption("browser"), encodeIfNeeded = FALSE)
url4 = paste("https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-","2020-10-09", ".xlsx", sep = "")
# url4 = paste("https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-",format(Sys.time(), "%Y-%m-%d"), ".xlsx", sep = "") # Better, but only works after data dayly actualisation
GET(url4, write_disk(tf <- tempfile(fileext = ".xlsx")))
## Response [https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-2020-10-09.xlsx]
## Date: 2020-10-10 19:17
## Status: 200
## Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
## Size: 2.76 MB
## <ON DISK> C:\Users\FRANCE~1\AppData\Local\Temp\RtmpwdvjKk\file239c49aa4747.xlsx
Summarizing data
data$GeoId = data$geoId
data$Cases = data$cases
data$Deaths = data$deaths
data$DateRep = data$dateRep
data$Month = data$month
df = data %>%
group_by(GeoId) %>%
summarise(cases = sum(Cases), deaths = sum(Deaths))
## `summarise()` ungrouping output (override with `.groups` argument)
df[df$GeoId=="UK",]$GeoId = "GB"
df[df$GeoId=="EL",]$GeoId = "GR"
head(df)
## # A tibble: 6 x 3
## GeoId cases deaths
## <chr> <dbl> <dbl>
## 1 AD 2568 54
## 2 AE 102929 438
## 3 AF 39693 1472
## 4 AG 111 3
## 5 AI 3 0
## 6 AL 14899 411
First graphs
ggplot(df[df$cases > 500000, ], aes(reorder(x = GeoId, X = cases), y = cases, fill = GeoId)) +
geom_bar(stat = "identity") +
theme_light() +
labs(title = "Země s výskytem případů Covid-19 nad 500.000",
x = "kód země",
y = "počty případů") +
guides(fill = "none")

ggplot(df[df$deaths > 30000, ], aes(reorder(x = GeoId, X = deaths), y = deaths, fill = GeoId)) +
geom_bar(stat = "identity") +
theme_light() +
#scale_y_log10() +
# scale_fill_stata("s2color") +
labs(title = "Země s počtem úmrtí na Covid-19 nad 30.000",
x = "kód země",
y = "počty úmrtí") +
guides(fill = "none")

Map - code provided by Patrik Galeta (except just small changes)
# Code by Patrik Galeta follows:
# Nahrat shapefile
world_shp = readOGR(paste(getwd(), "/shp_world", sep = ""),
layer = "TM_WORLD_BORDERS_SIMPL-0.3",
use_iconv = TRUE, encoding = "utf-8")
## OGR data source with driver: ESRI Shapefile
## Source: "D:\ownCloud2\!!!Vyuka\!KSS-KA1\shp_world", layer: "TM_WORLD_BORDERS_SIMPL-0.3"
## with 246 features
## It has 11 fields
## Integer64 fields read as strings: POP2005
# Spojeni shape data s df, mapove podklady se spoji s informaci o poctu pripadu
db <- merge(x = world_shp@data, y = df, by.x = "ISO2", by.y = "GeoId")
# Uprava shape file pro ggplot
world_fortified <- fortify(world_shp, region = "ISO2")
## Warning in RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid"): Ring Self-
## intersection at or near point -53.756366730000003 48.50326347
## Warning in RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid"): Ring Self-
## intersection at or near point -70.917236329999994 -54.70861816
## Warning in RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid"): Ring Self-
## intersection at or near point 5.3369464899999999 61.592775340000003
## Warning in RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid"): Ring Self-
## intersection at or near point 143.66192817999999 49.312211990000002
## SpP is invalid
## Warning in rgeos::gUnaryUnion(spgeom = SpP, id = IDs): Invalid objects found;
## consider using set_RGEOS_CheckValidity(2L)
world_fortified_df <- left_join(world_fortified, db, by=c("id"="ISO2"))
db = within(db, {
LAB = paste0(ISO2, ": ",cases)
})
# Mapa
g = ggplot() +
geom_polygon(data = world_fortified_df[world_fortified_df$REGION==c(150)&
world_fortified_df$id!="RU",],
aes(x = long, y = lat, group = group, fill = cases),
col = "grey44") +
geom_text(data = db[db$REGION==c(150)&db$ISO2!="RU",],
aes(x = LON, y = LAT, label = LAB), size = 2.2, col = "black") +
guides(size = F, fill = F) +
scale_fill_gradientn(colours = brewer.pal(n = 8, name = "Dark2")[-(1)])+
labs(title = paste0("Confirmed coronavirus cases by ", format(Sys.time(), "%d. %m. %Y"))) +
theme_void() +
theme(plot.title = element_text(face = "bold", size = 10))
ggplotly(g)
## Warning: `group_by_()` is deprecated as of dplyr 0.7.0.
## Please use `group_by()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.