Skip to content

Instantly share code, notes, and snippets.

@jstray
Created September 18, 2012 04:45
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 jstray/3741305 to your computer and use it in GitHub Desktop.
Save jstray/3741305 to your computer and use it in GitHub Desktop.
Apply multi-dimensional scaling to House of Lords voting history distance matrix, and plot
# -------------------------------- MDS plot ------------------------------
fit <- cmdscale(d,eig=TRUE, k=2) # k is the number of dim
x <- fit$points[,1]
y <- fit$points[,2]
# ]plot with colors corresponding to party
parties = factor(row.names(recentvotes))
plot(x, y, xlab="Coordinate 1", ylab="Coordinate 2", main="House of Lords voting", pch=19, col=parties)
legend('topright', legend = levels(parties), col=palette(), cex = 0.8, pch = 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment