In this exercise, we will revisit to the fabricated Bronze Age cemetery from the exercise in Week 3. The lab has sent you the results of the elemental composition analysis of bronze artefacts from this cemetery. The results are in an Excel spreadsheet.
Your task is to import these results into R, perform PCA and visualise the results using the ggplot() function, and determine whether the composition of bronze weapons differs from that of bronze jewellery and clothing components.
Use code rm(list = ls()) to clean your workspace
You have two ways how to import .xlsx into R
read.csv() function.Or:
readxl::read_excel() in the same way as read.csv() to import directly the .xlsx filedplyr::join_left() to connect the two tablesdplyr::mutate() create a new variable “category” where all artefacts from vector “list_weapons” will get value “weapon” and all artefacts from the vector “list_jewelry” will get value “jewelry”as.matrix()scale. = TRUE when conducting the PCA with prcomp()pca_result$x and coordinates of the elements in pca_result$rotationggplot()geom_point()paste0() to add values of variability to the x and y axis descriptionsplot_1 <- ggplot()+
geom_point(data = table_artefacts,
aes(x = PC1, y = PC2, color = category),
shape = 21)+
geom_point(data = table_elements,
aes(x = PC1, y = PC2),
shape = 4) +
geom_text(data = table_elements,
aes(x = PC1, y = PC2, label = element),
vjust = -0.5)+
scale_color_manual(
name = "artefact category:",
values = my_colors,
labels = c("jewelry", "weapon")
)+
labs(
title = "Principal Component Analysis",
x = paste0("PC1 (", variability_pc1, " % of variability)"),
y = paste0("PC2 (", variability_pc2, " % of variability)"),
caption = paste0("Number of artefacts: ", n_artefacts)
)+
theme_light()
plot_1