similarity2MDS (Source)

#!/usr/bin/env Rscript --vanilla
USAGE ="Usage: similarity2MDS CSVFILE OUTFILE
Take a tab delimited csv file with similarity matrix data and output a pdf with
2D MDS. The similarity matrix may be square or lower triangular
"
library(ggplot2)
library(ggrepel)

args <- commandArgs(TRUE)
if (any(grep("^(--help|-h)$", args), is.na(args[1]))){ 
  cat(USAGE)
  quit("no", 1)
  }
stopifnot(length(args) == 2)

data.sim <- as.dist(read.delim(args[[1]], row.names=1, header=TRUE))
data.dist <- 1 - (data.sim/max(data.sim))
fit <- as.data.frame(cmdscale(data.dist, k=2))
names(fit) <- c("x", "y")
pdf(args[[2]], width=7, height=7)
ggplot(data=fit) + geom_point(aes(x, y, size=3)
                  ) + geom_text_repel(
                              aes(x, y, label=rownames(fit)), 
                              segment.color="blue",
                              arrow = arrow(length = unit(0.01, 'npc'), 
                                            angle=15,
                                            type='closed'),
                              box.padding = unit(0.3, "lines"),
                              point.padding = unit(1.0, "lines")
                  ) + theme(legend.position = "none",
                              axis.title.x = element_blank(),
                              axis.title.y = element_blank(),
                              panel.grid.minor=element_blank(),
                              panel.grid.major=element_blank()
                  )
dev.off()

# If you're using MacOSX, the following line will automatically open the plot once it's made
# system(paste("open", args[[2]]))