-
Notifications
You must be signed in to change notification settings - Fork 0
/
MergeFilesPlotSameSep.R
45 lines (36 loc) · 1.68 KB
/
MergeFilesPlotSameSep.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
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 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))