Skip to content

Instantly share code, notes, and snippets.

@mw55309
Created Jun 27, 2016
Embed
What would you like to do?
d <- read.csv("http://www.electoralcommission.org.uk/__data/assets/file/0014/212135/EU-referendum-result-data.csv")
vec <- rep(1, nrow(d))
vec[d$Region=="Scotland"] <- 1
vec[d$Region=="North East"] <- 2
vec[d$Region=="North West"] <- 3
vec[d$Region=="East Midlands"] <- 4
vec[d$Region=="West Midlands"] <- 5
vec[d$Region=="Yorkshire and The Humber"] <- 6
vec[d$Region=="Northern Ireland"] <- 7
vec[d$Region=="Wales"] <- 8
vec[d$Region=="East"] <- 9
vec[d$Region=="London"] <- 10
vec[d$Region=="South East"] <- 11
vec[d$Region=="South West"] <- 12
order <- as.factor(vec)
nd <- cbind(d, order)
levels(nd$order) <- c("Scotland","North East","North West","East Midlands","West Midlands","Yorkshire and The Humber","Northern Ireland","Wales","East","London","South East","South West")
nd$prop <- log2(nd$Leave / nd$Remain)
nd$perc <- (nd$Leave / (nd$Leave + nd$Remain)) * 100
par(mar=c(4,12,2,2))
boxplot(perc ~ order, data=nd, las=2, horizontal=TRUE, ylim=c(0,100))
abline(v = 50, col = "red", lty=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment