comparison PCA_plot.R @ 9:2e8c9032e8d8 draft

Uploaded
author mb2013
date Tue, 20 May 2014 03:27:01 -0400
parents
children
comparison
equal deleted inserted replaced
8:0cb68fb9010f 9:2e8c9032e8d8
1 #Plottool makes a graph of Principal Components created with a Principal Component analysis.
2 #MB
3
4 #commands extracting of commandline
5 args <- commandArgs(TRUE)
6
7 #input files and options
8 input <- args[1]
9 main_title <- args[2]
10 x_title <- args[3]
11 y_title <- args[4]
12 x_column <- args[5]
13 y_column <- args[6]
14 names <- args [7] #name of every sample in one file
15 #output file
16 output <- args[8]
17
18 suppressMessages(library("geomorph")) #package geomorph
19
20 #reading of input files
21 read <- read.csv(file <- input,header = TRUE)
22 read2 <- scan(file <- names, what = "", quiet = TRUE)
23
24 pca1 <- read[,as.integer(x_column)] #principal component
25 pca2 <- read[,as.integer(y_column)] #principal component
26
27 png(output) #output in png format
28
29 #axis boundaries
30 minpca1 = min(pca1) - max(pca1)
31 maxpca1 = max(pca1) + max(pca1)
32 minpca2 = min(pca2) - max(pca2)
33 maxpca2 = max(pca2) + max(pca2)
34
35 #creating the plot with principal components and titels
36 suppressMessages(plot(pca1,pca2, main = main_title, xlab = x_title, ylab = y_title, pch=20,cex=0.6, xlim = c(minpca1,maxpca1), ylim=c(minpca2,maxpca2)))
37 #add labels to data points
38 text(pca1,pca2,labels = read2, pos = 2, cex = 0.7,col = heat.colors(35:40))
39
40 graphics.off()