annotate PCA_plot.R @ 18:a207e838f232 draft

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