Adrià Vilanova MartÃnez | 6785f9f | 2023-04-20 02:13:51 +0200 | [diff] [blame] | 1 | library(svglite) |
| 2 | library(tikzDevice) |
| 3 | |
| 4 | filename = 'regressio' |
| 5 | |
| 6 | args = commandArgs(trailingOnly=TRUE) |
| 7 | |
| 8 | table <- read.table(paste0('dades/', filename, '.txt'), sep=" ", dec='.', header=TRUE) |
| 9 | |
| 10 | fit <- lm(X ~ Y, data = table) |
| 11 | summary(fit) |
| 12 | |
| 13 | # Plot the data |
| 14 | plotall <- function() { |
| 15 | par(mar=c(4,4,0.5,0.5)) |
| 16 | plot(table$Y, table$X, pch = 4, xlab = "$\\sin(\\theta)$", ylab = "$\\frac{n \\lambda}{2}$ (pm)") |
| 17 | abline(fit, col = "#799B6F") |
| 18 | } |
| 19 | |
| 20 | svg(paste0('output/', filename, '.svg'), width = 4*0.82, height = 3*0.82) |
| 21 | plotall() |
| 22 | dev.off() |
| 23 | |
| 24 | if (length(args) < 1 || args[1] != "preview") { |
| 25 | tikz(paste0('output/', filename, '.tex'), width = 4*0.82, height = 3*0.82) |
| 26 | plotall() |
| 27 | dev.off() |
| 28 | } |