# Load chemRmetrics package - If not installed, refer to the guide file in the ChemRmetrics repository on GitHub library(chemRmetrics) # Load data from jdx files in 'Homogeneity Study Raw Data' folder data <- load_data('Homogeneity Study Raw Data', ftype = 'jdx', fstruc = 'Distance_Position_Replicate', delim = '_') # Remove diamond signal from all spectra trunc <- data_trunc(data, 4, 2350, 1850) # Interpolate the data between a range of 4000-400 cm-1, with a step size of 1 interp <- data_interp(trunc, 4, 4000, 400, 1) # Normalise the spectra to unity norm <- data_norm_mm(interp, 4) # Perform principal component analysis (also exports scree plot and loadings plots for first 7 PCs) pc_data <- pca(norm, 4, 7) # Create a 3D PCA scores plot using PC1, PC2, and PC3 and the 'Distance' variable for the colour and legend (marker size = 6) plot_3D(pc_data, 'Distance', 1, 2, 3, 6, colours = palette.colors(8, 'R4')) # Create a 3D PCA scores plot using PC1, PC2, and PC3 and the 'Position' variable for the colour and legend (marker size = 6) plot_3D(pc_data, 'Position', 1, 2, 3, 6, colours = c('#8B0069', '#5DD291'))