Adrià Vilanova Martínez | 42b8a89 | 2023-03-21 00:18:28 +0100 | [diff] [blame] | 1 | library(tikzDevice) |
| 2 | |
| 3 | nom <- 'Ra_aire' |
| 4 | scale <- 4 |
| 5 | |
| 6 | table <- read.table(paste0('dades/', nom, '.txt'), sep="\t", dec='.', header=TRUE) |
| 7 | |
| 8 | # Plot the data |
| 9 | plotall <- function() { |
| 10 | plot(table$Energy, table$Impulses, type="l", col="#EEEEFF", xlab="Energia (keV)", ylab="Comptes", ylim=c(0, 100)) |
| 11 | lines(table$Energy, table$ImpulsesSmooth, type="l") |
| 12 | |
| 13 | # Add arrows and text labels to the peaks |
| 14 | for (j in 1:nrow(peaks)) { |
| 15 | i <- peaks[j, 'indexes'] |
| 16 | label <- peaks[j, 'labels'] |
| 17 | arrows(table$Energy[i], table$ImpulsesSmooth[i] + scale*(if (j == 1) 5 else 3), table$Energy[i], table$ImpulsesSmooth[i] + scale*0.1, length = 0.05, code = 1, col = "#514E7E") |
| 18 | text(table$Energy[i], table$ImpulsesSmooth[i] + scale*(if (j == 1) 6.6 else 4.6), paste0(table$Energy[i], " keV", "\n", label), col = "#514E7E", cex = 0.75) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | # Els valors dins de c(...) són les files del fitxer de dades. |
| 23 | # Es resta 2 per trobar els índexs (2 columnes són headers). |
| 24 | indexes <- c(207, 327, 645) - 2 |
| 25 | labels <- c("\\textsuperscript{210}Po + \\textsuperscript{222}Rn", "\\textsuperscript{218}Po", "\\textsuperscript{214}Po") |
| 26 | peaks <- data.frame(indexes, labels) |
| 27 | |
| 28 | pdf(paste0('output/', nom, '.pdf'), width = 6, height = 5) |
| 29 | plotall() |
| 30 | dev.off() |
| 31 | |
| 32 | tikz(paste0('output/', nom, '.tex'), width = 6, height = 5) |
| 33 | plotall() |
| 34 | dev.off() |