Commits

Giovanni Marco Dall'Olio committed 52252e8

PLOTS: added a stub script to plot values by chromosomes, divided into facets. Other people have asked me to pass them a script for producing these type of plots

  • Participants
  • Parent commits 2473638

Comments (0)

Files changed (1)

src/scripts/plot_values_by_position.R

+
+# FUNCTION TO PLOT a subset of genes
+plot_subset_of_genes <- function(allscores, genes_to_plot){
+    usage = '
+    FUNCTION TO PLOT a subset of genes.
+
+    usage:
+
+        > scores = read.table("mytable.csv", header=T)
+        > head(scores)
+        position    gene    score
+        10000000    GENE1   0.3
+        20000000    GENE2   2.1
+        30000000    GENE2   2.1
+
+        > plot_subset_of_genes(scores, c("GENE1", "GENE2))
+        -> will plot all the scores for GENE1 and GENE2
+
+
+    '
+    scores_subset <- subset(allscores, gene %in% genes_to_plot)
+
+    # base qplot
+    p = qplot(data=scores_subset, x=position, y=score)
+
+    # plot each gene in a separate facet. Scales=free_x means that only the Y axis will be fixed.
+    p = p + facet_wrap(~gene, scales="free_x") +
+
+    # title of the plot. This may be different in other versions of ggplot2
+    p = p + ggtitle("Distribution of scores for a subset of genes") + 
+
+    # Rotate the X axis labels of 60 degrees, and align them to the right
+    p = p + theme(axis.text.x = element_text(angle = 60, hjust = 1))
+
+    # print the plot (necessary if inside a function)
+    print(p)
+}
+
+
+myscores = read.table("myscores_file.txt", header=T)
+# initialize output pdf file
+pdf("myoutput.pdf")
+# plot only a few genes
+plot_subset_of_genes(myscores, c("ALG1", "ALG2", "ALG3"))
+
+# close pdf 
+dev.off()