This commit is contained in:
Jan Nowak 2021-05-26 17:15:22 +02:00
parent 76257ec14b
commit 2d7bc98357
2 changed files with 3236 additions and 0 deletions

70
proj2/mapka.R Normal file
View File

@ -0,0 +1,70 @@
library(dplyr)
library(highcharter)
library(xts)
#install.packages("rworldmap")
library(rworldmap)
#install.packages("countrycode")
#library(countrycode)
#install.packages("rgeos")
library(rgeos)
library(ggplot2)
#install.packages("rgdal")
library(rgdal)
#install.packages("devtools")
#library(devtools)
library(dplyr)
library(viridis)
##install_github("dgrtwo/gganimate", ref = "26ec501")
#install.packages("hms")
library(hms)
#install.packages("gganimate")
library(gganimate)
library(zoo)
cov <- read.csv("proj2/max-covid.csv", header = TRUE)
#df <- data.frame(as.Date(cov$date, format="%Y-%m-%d"), cov$iso_code, cov$total_cases)
df <- data.frame(as.Date(cov$date), cov$iso_code, cov$total_cases)
colnames(df) <- c('date', 'iso', 'total_cases')
#df$date = format(df$date, "%Y-%m")
#dd <- df %>% group_by(iso, date)
#df %>% mutate(date2 = format(cov.date, "%Y-%m")) %>% group_by(cov.iso_code, date2) %>% summarise(total = sum(cov.total_cases))
#df = df[order(as.Date(df$cov.date, format="%Y-%m-%d")),]
casesmax = max(df$total_cases, na.rm=T)
casesmin = min(df$total_cases, na.rm=T)
wmap <- getMap(resolution="low")
#wmap <- spTransform(wmap, CRS("+proj=robin")) # reproject
wmap_df <- fortify(wmap, region = "ISO3")
wmap_df <- left_join(wmap_df, df, by = c('id'='cov.iso_code'))
ggplot(data=wmap_df, frame = date) +
geom_polygon(aes(x = long, y = lat, group = group, fill=cov.total_cases), color="gray90") +
scale_fill_viridis(name="Cases", begin = 0, end = 1, limits = c(casesmin,casesmax), na.value="gray99") +
theme_void() +
guides(fill = guide_colorbar(title.position = "top")) +
labs(title = "") +
theme( legend.position = c(.5, .08),
legend.direction = "horizontal",
legend.title.align = 0,
legend.key.size = unit(1.3, "cm"),
legend.title=element_text(size=17),
legend.text=element_text(size=13) )
#+
# transition_time(date)
#gganimate(o)
#gg_animate(o, "output4020_old.gif", title_frame =T,
# ani.width=1600, ani.height=820, dpi=800, interval = .4)

3166
proj2/month-covid.csv Normal file

File diff suppressed because it is too large Load Diff