-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRcode-RamanAnalysis-GitHub.R
More file actions
77 lines (59 loc) · 2.86 KB
/
Copy pathRcode-RamanAnalysis-GitHub.R
File metadata and controls
77 lines (59 loc) · 2.86 KB
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
70
71
72
73
74
75
76
77
#Raman spectroscopy of fibres - EAT project
# plot 40 raman measurement fibres ----------------------------
pathfibre = "~/Downloads/R-analysis/Raman" #put in your actual path where the text files are saved
setwd(pathfibre) #this is to indicate which directory to use
list_fibre = list.files(path=pathfibre, pattern="*.txt", full.names=FALSE) #create list of text files
raman_fibre <- data.frame(raman_shift = seq(100, 1600, by=1500/59411)) #create dataframe with raman shift only
for (i in 1:40) { #create a look to integrate all raman text files in the one dataframe
raman_datafibre <- scan(list_fibre[i])
toDelete <- seq(1, length(raman_datafibre), 2)
raman_datafibre <- raman_datafibre[-toDelete]
raman_fibre <- cbind(raman_fibre, raman_datafibre)
}
colnames(raman_fibre) <- c("raman_shift", list_fibre) #to give the respective text file name to all columns
#To repeat 5x to reduce the number of measurements to 1858 measurements.
toDelete2 <- seq(0, nrow(raman_fibre), 2)
last <- nrow(raman_fibre)/2 + 1
toDelete2 <- toDelete2[-last]
raman_fibre <- raman_fibre[-toDelete2,]
toDelete2 <- seq(0, nrow(raman_fibre), 2)
last <- nrow(raman_fibre)/2 + 1
toDelete2 <- toDelete2[-last]
raman_fibre <- raman_fibre[-toDelete2,]
toDelete2 <- seq(0, nrow(raman_fibre), 2)
last <- nrow(raman_fibre)/2 + 1
toDelete2 <- toDelete2[-last]
raman_fibre <- raman_fibre[-toDelete2,]
toDelete2 <- seq(0, nrow(raman_fibre), 2)
last <- nrow(raman_fibre)/2 + 1
toDelete2 <- toDelete2[-last]
raman_fibre <- raman_fibre[-toDelete2,]
toDelete2 <- seq(0, nrow(raman_fibre), 2)
last <- nrow(raman_fibre)/2 + 1
toDelete2 <- toDelete2[-last]
raman_fibre <- raman_fibre[-toDelete2,]
#Plot
library(ggplot2)
library(reshape2)
raman_fibre_40 <- raman_fibre
raman_fibre_40melt <- melt(raman_fibre_40, id.vars = 'raman_shift', variable.name = 'fibre')
ggplot(raman_fibre_40melt, aes(x=raman_shift, y=value, color=fibre)) +
geom_line(size=0.2) + scale_x_continuous(breaks=seq(100, 1600, 100)) +
theme(legend.position="none") + ggtitle("fibre")
#Plot only a few
library(ggplot2)
library(reshape2)
raman_fibre_few <- raman_fibre[,c(1,3,25,40)]
raman_fibre_fewmelt <- melt(raman_fibre_few, id.vars = 'raman_shift', variable.name = 'fibre')
ggplot(raman_fibre_fewmelt, aes(x=raman_shift, y=value, color=fibre)) +
geom_line(size=0.2) + scale_x_continuous(breaks=seq(100, 1600, 100)) +
theme(legend.position="left") + ggtitle("fibre")
#Fibers were manually separated, assigned and added into a tablw, than the Pie chart made
fibre_counts <- read.csv("~/Downloads/R-analysis/fibre_counts.csv", header = T)
slices <- fibre_counts$counts
lbls <- fibre_counts$types
pct <- round(fibre_counts$counts/sum(fibre_counts$counts)*100)
lbls <- paste(lbls, pct) # add percents to labels
lbls <- paste(lbls,"%",sep="") # ad % to labels
pie(slices,labels = lbls, col=rainbow(length(lbls)),
main="Fibre-counts")