### This script reproduces the visualization of political party classifications. Done by Dimiter Toshkov http://www.dimiter.eu Last updated 02/01/2019. # Load the data file. The data comes from the appendix to the paper and has been coded by Matthijs Rooduijn. # I have only shortened some party names and removed two parties that had zeroes on all attributes. d<-read.table('http://dimiter.eu/Visualizations_files/party_categorization/party_categorization.txt', sep='\t', header=T) #read the datafile d<-d[order(d$country, d$populist,d$far_left, d$far_right),] #sort as desired by column name, in this case by country d<-d[order(d$populist,d$far_left, d$far_right, d$eurosceptic),] #alternative sort by populist status #these libraries are needed to get custom fonts library(extrafont) #to use custom fonts library(sysfonts) #to load custom fonts library(jsonlite) #needed by sysfonts library(RCurl) library(showtext) #to use the custom fonts font_add_google('Cairo') #get the fonts font_add_google("Montserrat") showtext_auto() #this is to turn on the custom fonts availability showtext_opts(dpi = 92) #set the resolution: 96 is default #get some named colors background.color=rgb(255, 246, 229, max=255) #color for the background dark.color=rgb(45, 45, 68, max=255) # dark color main.color=rgb(255, 0, 51, alpha=205, max=255) #main color axiscolors<-c(dark.color, dark.color, main.color, dark.color, dark.color) np<-75 #how many parties will be plotted #pdf("F:/category2.pdf",width=15, height= 2 + np*0.6) png("F:/category2.png",width=1500, height= 200 + np*50, res=92) #allow for space for vertical space for each party par(mfrow=c(1,1), oma=c(2,1,4,1), par(mar=c(0,20,1,11)), bg=background.color, bty='n', family='Montserrat') plot(xlim=c(1,5), ylim=c(1,np), NULL, axes=F, xlab="", ylab="", main='', cex.main=1, col.main=dark.color, font.main=1) #start with an empty plot Map(axis, side=3, at=1:5, col.axis=axiscolors, labels=colnames(d)[2:6], lwd=0, las=1, line=-5, cex.axis=2,font=2, tck=-0.1) axis(3,at=1:5,labels=FALSE, tck=-0.1, line=05, lwd=0) #this is to get the axes labels have different colors Map(axis, side=1, at=1:5, col.axis=axiscolors, labels=colnames(d)[2:6], lwd=0, las=1,line=-5, cex.axis=2,font=2, tck=-0.1) axis(1,at=1:5,labels=FALSE, tck=-0.1, line=05, lwd=0) axis (2, font=3, tck=-0.1, col=background.color, col.axis='black', at=(1:np), line=0, labels=d[1:np,1], cex.axis=1.5, las=1) axis (4, font=1, tck=-0.1, col=background.color, col.axis=dark.color, at=(1:np), line=0, labels=d[1:np,7], cex.axis=1.5, las=1) #title mtext(expression(bold(' Political parties classified along five dimensions')),line=2, font=1, at=0, col=dark.color, cex=3.2, adj=0, padj=1, outer=T) #data statement mtext(text=expression("Data: " * phantom("Matthijs Rooduijn")), side=1, line=-1, outer=T, font=1, family='Cairo', col=dark.color, cex=2.0, adj=0, padj=1) mtext(text=expression(phantom("Data: ") * "Matthijs Rooduijn"),side=1, line=-1, outer=T, font=1, family='Cairo', col=main.color, cex=2.0, adj=0, padj=1) #signature mtext(text=expression(phantom('Chart: ') * "@DToshkov"), side=1, line=-1, outer=T, font=1, family='Cairo', col=main.color, cex=2.0, adj=1, padj=1) mtext(text=expression('Chart: ' * phantom("@DToshkov")), side=1, line=-1, outer=T, font=1, family='Cairo', col=dark.color, cex=2.0, adj=1, padj=1) #add the line segments for (i in 1:np){ start.l=head(grep("1", d[i,2:6]), n=1) #get the first non-zero element in the relevant (non-text) columns end.l=tail(grep("1", d[i,2:6]), n=1) #get the last non-zero element segments(x0=start.l, x1=end.l, y0=i, y1=i, col='grey', lwd=6) #draw a line between these twp for (j in 2:(ncol(d)-1)){ points(x=j-1, y=i, pch=19, cex=6.75, col=ifelse(j==4 & d[i,j]==1,"red", ifelse(d[i,j]==1, 'grey', 'white'))) #draw a grey dot for 1s, white for 0s, and red for the attribute of key interest } } dev.off() #close the plot #now get the distribution summary plots with the UpSetR library library(UpSetR) #pdf("F:/category_all.pdf",width=12, height= 10) png("F:/category_all.png",width=1200, height= 900, res=92) par(mfrow=c(1,1), oma=c(2,1,4,1), #par(mar=c(0,20,1,11)), bg=background.color, bty='n', family='Montserrat') upset(d, order.by = "freq", nsets = 5, number.angles = 0, point.size = 3.5, line.size = 2, mainbar.y.label = "Dimension Intersections", sets.x.label = "Parties per dimension", mb.ratio = c(0.5, 0.5), text.scale = c(1.5, 1.3, 1.3, 1.3, 2, 1.5)) #empty.intersections = "on" dev.off()