Skip to content

Instantly share code, notes, and snippets.

@johandahlberg
Last active December 26, 2015 13:20
Show Gist options
  • Save johandahlberg/a8c1ed986d8d43bb7e73 to your computer and use it in GitHub Desktop.
Save johandahlberg/a8c1ed986d8d43bb7e73 to your computer and use it in GitHub Desktop.
Quick plot of income differences between men and women in the period 1991 to 2013 in Sweden.
# Licence:
# https://creativecommons.org/licenses/by/3.0/
library(ggplot2)
library(reshape2)
library(dplyr)
# Data:
# Downloaded at: http://www.statistikdatabasen.scb.se/pxweb/sv/ssd/START__HE__HE0110__HE0110A/SamForvInk2/?rxid=c58583e1-7fc3-418a-9395-0300e138fe7f
# Sammanräknad förvärvsinkomst, medianinkomst för boende i Sverige den 31/12, tkr efter region, kön, ålder och år
data <- read.csv("male_vs_female_median_income.csv")
data <- t(data)
colnames(data) <- c("Men", "Women", "Total")
data <- data[3:nrow(data),]
data <- data.frame(cbind(data, Year = as.numeric(gsub("X", "", rownames(data)))))
data$Men <- as.numeric(as.character(data$Men))
data$Women <- as.numeric(as.character(data$Women))
data$Total <- as.numeric(as.character(data$Total))
data$Difference <- (data$Women / data$Men) * 100
data$Men.Difference <- 100 - data$Difference
m.data <- melt(data, id.vars = c("Year"), measure.vars =c("Difference", "Men.Difference"))
m.data <- m.data %>% filter(Gender != "Total")
ggplot(m.data) +
geom_bar(aes(x = Year, y = value, fill=variable), stat="identity") +
theme_classic(base_size = 18) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Year") +
ylab("Percent of mens income") +
ggtitle("Womens median income as percent of mens \nmedian income in Sweden 1991 to 2013") +
scale_fill_brewer(palette="Dark2", labels=c("Women", "Men"), name="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment