-
Notifications
You must be signed in to change notification settings - Fork 0
/
MergeFilesPlotMaster.R
69 lines (56 loc) · 2.24 KB
/
MergeFilesPlotMaster.R
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
setwd("./cleaned_raw")
# This will generate a list of files to be merged
file_list <- list.files()
# The following for loop then creates the dataframe and combines files into it
for (file in file_list){
# if the merged dataset doesn't exist, create it
if (!exists("dataset")){
dataset <- read.table(file, header=TRUE, sep="")
}
# if the merged dataset does exist, append to it
if (exists("dataset")){
temp_dataset <-read.table(file, header=TRUE, sep="")
dataset<-merge(dataset, temp_dataset)
rm(temp_dataset)
}
}
# Makes the first column as the index values
rownames(dataset) <- dataset$Wavelength
# The next line exports the data frame into a tab-delimited text file
write.table(dataset, "combineddataset.txt", sep="\t")
# Option 1: generate ggplots for each wavelength and make a pdf with each graph as a separate page
require(ggplot2)
start <- 2
stop <- ncol(dataset)
plot_list <- list()
for(i in start:stop){
graphy <- ggplot(dataset,aes_string(x=names(dataset)[1],y=names(dataset)[i])) + geom_line()
plot_list[[i]] <- graphy
}
#for (i in start:stop) {
# file_name <- paste("Spectrum_plot_for_", i, "nm.pdf", sep="")
# pdf(file_name)
# print(plot_list[[i]])
# dev.off()
#}
#pdf("Spectra_plots_different_wavelength.pdf")
#for (i in 1:stop) {
# print(plot_list[[i]])
#}
#dev.off()
# Option 2: generate all on the same plot using matplot
pdf('Excitation_by_wavelength_sameplot.pdf')
nn <- ncol(dataset[2:ncol(dataset)])
matplot(dataset[,2:ncol(dataset)], type = 'l', lty = "solid", ann=TRUE, xlab = "Wavelength", ylab = "" )
legend("topright", colnames(dataset[2:ncol(dataset)]), col=seq_len(nn), cex = 0.8, fill=seq_len(nn))
# Option 3: generate all plots separately, but on the same page using timeseries
# Then this creates a pdf file of the plots
pdf('Excitation_by_wavelength_separateplots.pdf')
plot.ts(dataset[2:ncol(dataset)], ann=FALSE); title(main = "Separate Excitation Plots", xlab = "Wavelength")
### Under development -------------------------
# require(ggplot2)
# require(reshape2)
# df <- melt(dataset , id.vars = 'Wavelength', variable.name = 'series')
# plot on same grid, each series colored differently --
# good if the series have same scale
# ggplot(df, aes(Wavelength,value)) + geom_line(aes(colour = series))