plotScatter.R 1.55 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
library(reshape2)
library(ggplot2)
library(argparse)

parser <- ArgumentParser(description='Process some integers')
parser$add_argument('--input', dest='input', type='character', help='Input tsv file', required=TRUE)
parser$add_argument('--output', dest='output', type='character', help='Output png file', required=TRUE)
parser$add_argument('--width', dest='width', type='integer', default = 500)
parser$add_argument('--height', dest='height', type='integer', default = 500)
parser$add_argument('--xlabel', dest='xlabel', type='character')
parser$add_argument('--ylabel', dest='ylabel', type='character', required=TRUE)
parser$add_argument('--llabel', dest='llabel', type='character')
parser$add_argument('--title', dest='title', type='character')
parser$add_argument('--removeZero', dest='removeZero', type='character', default="false")

arguments <- parser$parse_args()

png(filename = arguments$output, width = arguments$width, height = arguments$height)

DF <- read.table(arguments$input, header=TRUE)

if (is.null(arguments$xlabel)) xlab <- colnames(DF)[1] else xlab <- arguments$xlabel

colnames(DF)[1] <- "Rank"

DF1 <- melt(DF, id.var="Rank")

if (arguments$removeZero == "true") DF1 <- DF1[DF1$value > 0, ]
if (arguments$removeZero == "true") print("Removed 0 values")

ggplot(DF1, aes(x = Rank, y = value, group = variable, color = variable)) +
  xlab(xlab) +
  ylab(arguments$ylabel) +
  guides(fill=guide_legend(title=arguments$llabel)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8)) +
  ggtitle(arguments$title) +
  theme_bw() +
  geom_point()

dev.off()