Skip to content

Instantly share code, notes, and snippets.

@marcbeldata
Last active October 3, 2017 21:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcbeldata/3cfd6a168d86fe411a1f5f79d67e57d4 to your computer and use it in GitHub Desktop.
Save marcbeldata/3cfd6a168d86fe411a1f5f79d67e57d4 to your computer and use it in GitHub Desktop.
################################################################################
#
# Marc Belzunces (Twitter: @marcbeldata)
# marcbeldata.github.io 2017-07-22
#
# Playing with ggjoy.
# Evolution of Indy and Unionist vote by municipality
# in Catalan regional elections (1980-2015)
#
################################################################################
library(tidyverse)
library(ggjoy)
library(forcats)
library(viridis)
#Data obtained and processed from Idescat.cat
df <- read_csv("Catalan Parliament Indy_Unio 1980-2015.csv")
#Two geom_joy
#Plot1
df %>%
ggplot(aes(y = as.factor(Year) %>% fct_rev())) +
geom_joy(aes(x = Indy_percent), fill = "red", alpha = 0.6)+
geom_joy(aes(x = Unio_percent), fill = "blue", alpha = 0.6) +
labs(x = "Vote (%)",
y = "Election's Year",
title = "Indy vs Unionist vote in Catalan elections",
subtitle = "Analysis unit: municipalities (n = 949) | Blue: unionist vote. Red: indy vote",
caption = "Marc Belzunces (@marcbeldata) | Source: Idescat") +
theme_minimal(base_size = 15)
#One geom_joy
df2 <- df %>%
gather(Indy_percent, Unio_percent, key = "Option", value = "Percentage") %>%
arrange(Municipality, Year)
#Plot2
df2 %>%
ggplot(aes(y = as.factor(Year) %>% fct_rev())) +
geom_joy(aes(x = Percentage, fill = Option, alpha = 0.8)) +
scale_fill_manual(values = c("Red", "Blue")) +
labs(x = "Vote (%)",
y = "Election's Year",
title = "Indy vs Unionist vote in Catalan elections",
subtitle = "Analysis unit: municipalities (n = 949) | Blue: unionist vote. Red: indy vote",
caption = "Marc Belzunces (@marcbeldata) | Source: Idescat") +
theme_minimal(base_size = 15) +
theme(legend.position = "none")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment