# 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 'Inside-Outside-Filament Raw Data' folder raw_data <- load_data('Inside-Outside-Filament Raw Data', ftype = 'jdx', fstruc = 'Brand_Filament-Type_Colour_Location_Replicate', delim = '_') # Remove diamond signal from all spectra trunc <- data_trunc(raw_data, 6, 2350, 1850) # Interpolate the data between a range of 4000-400 cm-1, with a step size of 1 interp <- data_interp(trunc, 6, 4000, 400, 1) # Normalise the spectra to unity norm <- data_norm_mm(interp, 6) # Perform principal component analysis (also exports scree plot and loadings plots for first 7 PCs) pc_data <- pca(norm, 6, 7) # Create a 3D PCA scores plot using PC1, PC2, and PC3 and the 'Location' variable for the colour and legend (marker size = 5) plot_3D(pc_data, 'Location', 1, 2, 3, 5, colours = c('#A75529', '#8B0069')) # Load data from jdx files in 'Printed-Filament Raw Data' folder proj_data <- load_data('Printed Raw Data', ftype = 'jdx', fstruc = 'Brand_Filament-Type_Colour_Location_Replicate', delim = '_') # Remove diamond signal from all spectra trunc_proj <- data_trunc(proj_data, 6, 2350, 1850) # Interpolate the data between a range of 4000-400 cm-1, with a step size of 1 interp_proj <- data_interp(trunc_proj, 6, 4000, 400, 1) # Normalise the spectra to unity norm_proj <- data_norm_mm(interp_proj, 6) # Projecting the Printed-Filament data onto the previously established PCA model for the inside-outside data pc_data_proj <- pca_proj(norm, norm_proj, 6, 7) # Create a 3D PCA scores plot with the projected data set using PC1, PC2, and PC3 and the 'Location' variable for the colour and legend (marker size = 5) plot_3D(pc_data_proj, 'Location', 1, 2, 3, 5, c('#A75529', '#8B0069', '#5DD291'), proj = TRUE)