#Display EDX spectrum from psma file ##Import the different spectra files read.table(sep = ",", file = "/path/to/file.psmsa") -> EDX_data #assigning first column to keV and second column to counts EDX_data[,1] -> KeV EDX_data[,2]-> counts # Libraries library(ggplot2) # create data data <- data.frame(KeV,counts) # Plot function plot_spectrum <- function(data) { # data[,1] -> KeV # data[,2]-> counts ggplot(data, aes(x = KeV, y = counts)) + geom_area(fill = "#0190a2", alpha = 0.4) + #color to fill under the line geom_line(color = "blue", size = 0.5) + #color and thickness of the line scale_x_continuous(n.breaks = 10, limits = c(0, 20)) + #number of x-axis values diplayed, limit values of the x axis theme(axis.text.x = element_text(angle = 90)) + #rotate x-axis labels 90° geom_vline(xintercept = c(0.5, 1.09, 1.74, 2.12, 2.042, 2.048), linetype = "dotted", size = 0.5) + #diplay vertical dotted lines where the expected peaks are ggtitle(paste("Spectrum Plot -", deparse(substitute(data)))) + # Dynamic title based on data name xlab("KeV") + # Add x-axis label ylab("Counts") # Add y-axis label } #Create plot plot_spectrum(EDX_data)