Skip to content

Instantly share code, notes, and snippets.

rm(list=ls())
library(memisc)
library(assertthat)
library(sqldf)
library(magrittr)
library(dplyr)
library(reshape2)
library(ggplot2)
library(oz)
library(scatterpie)
map_data(map, region = ".", exact = FALSE, ...)
borders(database = "world", regions = ".", fill = NA,
colour = "grey50", xlim = NULL, ylim = NULL, ...)
readOGR(dsn, layer, verbose = TRUE, p4s=NULL,
stringsAsFactors=default.stringsAsFactors(),
drop_unsupported_fields=FALSE,
pointDropZ=FALSE, dropNULLGeometries=TRUE,
useC=TRUE, disambiguateFIDs=FALSE, addCommentsToPolygons=TRUE,
encoding=NULL, use_iconv=FALSE, swapAxisOrder=FALSE, require_geomType = NULL,
integer64="no.loss", GDAL1_integer64_policy=FALSE)
fortify(model, data, ...)
# Using borders()
mapplot2 <- ggplot(data = final_data, aes(x=longitude, y=latitude), group = country) +
borders("world", colour="gray50", fill="gray50")
mapplot2
# Using shapefile / geom_polygon
SHAPE_FILE_PATH = "./Data/World_Countries/World_Countries.shp"
world <- readOGR(dsn = SHAPE_FILE_PATH)
world <- fortify(world)
mapplot3 <- ggplot(data = world, aes(long, lat, group=group)) +
geom_polygon(color = "white", fill = "gray50")
mapplot3
# Using map_data()
worldmap <- map_data ("world")
mapplot1 <- ggplot(worldmap) +
geom_map(data = worldmap, map = worldmap, aes(x=long, y=lat, map_id=region), col = "white", fill = "gray50") +
geom_scatterpie(aes(x=longitude, y=latitude, group = country, r = multiplier*6),
data = final_data, cols = colnames(final_data[,c(2:11)]))
mapplot1
# Using map_data()
worldmap <- map_data ("world")
mapplot1 <- ggplot(worldmap) +
geom_map(data = worldmap, map = worldmap,
aes(x=long, y=lat, map_id=region), col = "white", fill = "gray50")
mapplot1
# Using map_data()
worldmap <- map_data ("world")
mapplot1 <- ggplot(worldmap) +
geom_map(data = worldmap, map = worldmap, aes(x=long, y=lat, map_id=region), col = "white", fill = "gray50") +
geom_scatterpie(aes(x=longitude, y=latitude, group = country, r = multiplier*6),
data = final_data, cols = colnames(final_data[,c(2:11)])) +
xlim(-20,60) + ylim(10, 75) +
scale_fill_brewer(palette = "Paired") +
geom_text(aes(x=longitude, y=latitude, group = country, label = country), data = final_data, stat = "identity",