Skip to content

Instantly share code, notes, and snippets.

@oskar-j
Created February 27, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskar-j/241e39dc239ef0d4fbca7fe064b44827 to your computer and use it in GitHub Desktop.
Save oskar-j/241e39dc239ef0d4fbca7fe064b44827 to your computer and use it in GitHub Desktop.
Map of women's suffrage in Europe #DataIsBeautiful #1
library(ggplot2)
library(grid)
library(rworldmap)
library(grid)
# Data sources:
# https://en.wikipedia.org/wiki/Timeline_of_women%27s_suffrage
# http://womensuffrage.org/?page_id=97
# Get the world map
worldMap <- getMap()
# Member States of the European Union
europeanUnion <- c("Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus",
"Czech Rep.", "Denmark", "Estonia", "Finland", "France",
"Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia",
"Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland",
"Portugal", "Romania", "Slovakia", "Slovenia", "Spain",
"Sweden", "United Kingdom")
europeanUnion <- c(europeanUnion, 'Belarus', 'Ukraine', 'Switzerland',
'Moldova', 'San Marino', 'Albania', 'Macedonia', 'Turkey',
'Norway', 'Georgia', 'Armenia', 'Russia', 'Iceland')
# Select only the index of states member of the E.U.
idxEurope <- which(worldMap$REGION == 'Europe')
europeanDataTable <- data.frame(country = europeanUnion, value = c('1918', '1948', '1944', '1945', '1960',
'1920', '1915', '1917', '1906', '1945',
'1918', '1952', '1945', '1928', '1945',
'1905', '1917', '1919', '1947', '1919', '1918',
'1976', '1946', '1920', '1945', '1931',
'1921', '1928', '1917', '1917', '1990',
'1918', '1973', '1920', '1946', '1934',
'1913', '1919', '1917', '1917', '1915'),
stringsAsFactors=FALSE)
europeanDataTable$value <- as.numeric(europeanDataTable$value)
# Extract longitude and latitude border's coordinates of members states of E.U.
europeCoords <- lapply(idxEurope, function(i){
df <- data.frame(worldMap@polygons[[i]]@Polygons[[1]]@coords)
df$region =as.character(worldMap$NAME[i])
colnames(df) <- list("long", "lat", "region")
return(df)
})
europeCoords <- do.call("rbind", europeCoords)
europeCoords$value <- europeanDataTable$value[match(europeCoords$region, europeanDataTable$country)]
# Plot the map
P <- ggplot() + geom_polygon(data = europeCoords, aes(x = long, y = lat, group = region, fill = value),
colour = "black", size = 0.1) +
coord_map(xlim = c(-13, 47), ylim = c(34, 71))
P <- P + scale_fill_gradient2(breaks = seq(1900, 2000, 10), name = "Year of introducing full suffrage",
low = "skyblue1", mid="mediumblue", midpoint=1950, high = "navyblue",
na.value = "grey50")
P <- P + theme(#panel.grid.minor = element_line(colour = NA), panel.grid.minor = element_line(colour = NA),
panel.background = element_rect(fill = NA, colour = NA),
axis.text.x = element_blank(),
legend.key.size = unit(3.5, 'lines'), # 3.5 for export to png, width is 1600
axis.text.y = element_blank(), axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(), axis.title = element_blank(),
#rect = element_blank(),
plot.margin = unit(0 * c(-1.5, -1.5, -1.5, -1.5), "lines"))
P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment