# 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 'Market Survey Raw Data' folder raw_data <- load_data('Markey Survey Raw Data', ftype = 'jdx', fstruc = 'Brand_Filament_Colour_Form_Replicate', delim = '_') # Remove diamond signal from all spectra trunc <- data_trunc(raw_data, 6, 2340, 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 'Filament' variable for the colour and legend (marker size = 3) plot_3D(pc_data, 'Filament', 1, 2, 3, 3, c('#A75529', '#5DD291', '#8B0069')) # The following for-loop was used to adjust filament-type to be just PLA, ABS, and PETG (e.g. PLA+ -> PLA, PETG-CF -> PETG ...etc) for (i in 1:nrow(raw_data)){ if (raw_data[i, 3] == 'PLA+'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Flex'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Wood'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Rainbow'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-CF'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Tough'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Bicolour'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Copper'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Marble'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'PLA-Twinkling'){ raw_data[i, 3] <- 'PLA' } else if (raw_data[i, 3] == 'ABS+'){ raw_data[i, 3] <- 'ABS' } else if (raw_data[i, 3] == 'PETG-CF'){ raw_data[i, 3] <- 'PETG' } } # The remainder of the script is repeat of the above data analysis using the simplified PLA, ABS, and PETG labels # to investigate the grouping of the main polymer classes trunc_2 <- data_trunc(raw_data, 6, 2340, 1850) interp_2 <- data_interp(trunc_2, 6, 4000, 400, 1) norm_2 <- data_norm_mm(interp_2, 6) pc_data_2 <- pca(norm_2, 6, 7) pc_data_cut <- pca(norm_cut, 6, 7) plot_3D(pc_data_cut, 'Filament', 1, 2, 3, 3, colours = c('#A75529', '#5DD291', '#8B0069'))