| library(tikzDevice) |
| |
| nom <- 'Calibrat_Ra' |
| scale <- 4 |
| |
| table <- read.table(paste0('dades/', nom, '.txt'), sep="\t", dec='.', header=TRUE) |
| |
| # Plot the data |
| plotall <- function() { |
| plot(table$Energy, table$Impulses, type="l", col="#EEEEFF", xlab="Energia (keV)", ylab="Comptes", ylim=c(0, 100)) |
| lines(table$Energy, table$ImpulsesSmooth, type="l") |
| |
| # Add arrows and text labels to the peaks |
| for (j in 1:nrow(peaks)) { |
| i <- peaks[j, 'indexes'] |
| label <- peaks[j, 'labels'] |
| arrows(table$Energy[i], table$ImpulsesSmooth[i] + scale*3, table$Energy[i], table$ImpulsesSmooth[i] + scale*0.1, length = 0.05, code = 1, col = "#514E7E") |
| text(table$Energy[i], table$ImpulsesSmooth[i] + scale*4.6, paste0(table$Energy[i], " keV", "\n", label), col = "#514E7E", cex = 0.75) |
| } |
| } |
| |
| # Els valors dins de c(...) són les files del fitxer de dades. |
| # Es resta 2 per trobar els índexs (2 columnes són headers). |
| indexes <- c(396, 492, 581, 830) - 2 |
| labels <- c("\\textsuperscript{226}Ra", "\\textsuperscript{210}Po + \\textsuperscript{222}Rn", "\\textsuperscript{218}Po", "\\textsuperscript{214}Po") |
| peaks <- data.frame(indexes, labels) |
| |
| pdf(paste0('output/', nom, '.pdf'), width = 6, height = 5) |
| plotall() |
| dev.off() |
| |
| tikz(paste0('output/', nom, '.tex'), width = 6, height = 5) |
| plotall() |
| dev.off() |