How to insert spatial network plot to a ggplot
library(rgeos)
library(rgdal)
library(dplyr)
require(maps)
require(viridis)
library(ggplot2)
library(spdep)
some.eu.countries <- c(
"Portugal", "Spain", "France", "Switzerland", "Germany",
"Austria", "Belgium", "UK", "Netherlands",
"Denmark", "Poland", "Italy",
"Croatia", "Slovenia", "Hungary", "Slovakia",
"Czech republic"
)
# Retrievethe map data
some.eu.maps <- map_data("world", region = some.eu.countries)
# Compute the centroid as the mean longitude and lattitude
region.lab.data <- some.eu.maps %>%
group_by(region) %>%
summarise(long = mean(long), lat = mean(lat))
cns <- knearneigh(cbind(region.lab.data$long, region.lab.data$lat), k=3, longlat=T)
scnsn <- knn2nb(cns, row.names = NULL, sym = T)
cns
scnsn
cS <- nb2listw(scnsn)
cS
summary(cS)
# Plotting neighbours network
plot(cS, cbind(region.lab.data$long, region.lab.data$lat))
# Now plotting countries
ggplot(some.eu.maps, aes(x = long, y = lat)) +
geom_polygon(aes( group = group, fill = region), colour = "black")+
geom_point(aes(region.lab.data$long, region.lab.data$lat), data = region.lab.data, size = 6)
I would like to insert #Plotting neighbours network to a # Now plotting countries in another words I would like to have a ggplot of countries and also see network of neighbours in it.
