library(ggplot2)
library("rworldmap")
library(igraph)
library(ape)
library(ggnetwork)
library(extrafont)
library(cowplot)
# load data -------------------------------------------
<- as.data.frame(data.table::fread("https://raw.githubusercontent.com/eparker12/nCoV_tracker/master/input_data/countries_codes_and_coordinates.csv"))
countries %>%filter(country=="United States")
countries<-read.csv("day18_connections/worldcities.csv")
worldload("day18_connections/dist2009c.RData")
# manipulations -------------------------------------------
= attr(dist2009c, "Label")
country09 = ape::mst(dist2009c)
mstree2009 = graph.adjacency(mstree2009, mode = "undirected")
gr09
= match(country09, countries$country,world$country)
mat
= data.frame(
coords2009 lat = countries$latitude[mat],
lon = countries$longitude[mat],
country = country09)
= cbind(
layoutCoordinates x = jitter(coords2009$lon, amount = 15),
y = jitter(coords2009$lat, amount = 8))
= names(table(country09)[which(table(country09) > 1)])
labc = match(labc, countries$country,world$country)
matc
= data.frame(
dfc latc = countries$latitude[matc],
lonc = countries$longitude[matc],
labc)
= dfc
dfctrans 1] = (dfc[,1] + 31) / 93
dfctrans[, 2] = (dfc[,2] + 105) / 238
dfctrans[,
= ggnetwork(gr09, arrow.gap = 0, layout = layoutCoordinates)
ggeo09
# plotting -----------------------------------------------
<- ggplot(ggeo09, aes(x = x, y = y, xend = xend, yend = yend)) +
g geom_edges(color = "black", alpha = 0.5, curvature = 0.1) +
geom_nodes(aes(color = name), size = 2) +
theme_void() +
geom_label(data = dfctrans, aes(x = lonc, xend = lonc, y = latc, yend = latc,
label = labc, fill = labc),
colour = "white", alpha = 0.5, size = 3) +
labs(
caption= "Viz Federica Gazzelloni - DataSource:stanford.edu - Connections Day18") +
theme(legend.position = "none")
<- ggdraw(g) + draw_label(
plot "Connections Day18 - Distances in World Countries",
fontface = 'bold',
x = 0.1,y=0.99,
hjust = 0
+
) theme_cowplot(font_size = 14)
# saving ######################################
::agg_png(here::here("day18_connections", "connections_day18.png"),
raggres = 320, width = 14, height = 8, units = "in")
plot
dev.off()
Connections Day 18
https://web.stanford.edu/class/bios221/book/Chap-Graphs.html https://github.com/jtichon/ModernStatsModernBioJGT/tree/master/data https://simplemaps.com/data/world-cities