I have used this piece of script to draw the PCA based on eigenvalue and eigenvector
percentage <- round((eigenval/(sum(eigenval))*100), 2)
percentage <- as.matrix(percentage)
percentage <- paste0(names(percentage), " (", percentage, "%)")
Names <- c ("mn27hd", "mdkk987", "mnsdnu83", "sjednu83", "bjeo972s")
pop.colour <- c("blue", "red", "green", "orange", "brown")
ggplot(eigenvec, aes(x=PC1, y=PC2, colour=pop.colour, label=Names)) +
geom_point(size=3) + geom_text(aes(label=Names), hjust=0, vjust=-0.5) + xlab(percentage[1]) + ylab(percentage[2])
how can I:
change the xlab and ylab names to show as: PC1 (36.61%), PC2 (33.7%)?
move only the pink label slightly left-side cause when I do it generally then the two left labels go outside the image or too close to the edge?
change the legend name and categories from the colour to the population name?
Thanks the legend worked. the PC1 and PC2 axes didn't! it says:
that is how my percentage looks like
I can only adjust the
hjust=0.4
without throwing the two green and blue labels out of the graph! which is still not enough for the purple label to be fully in! I was thinking if it is possible to change the dimensions of the graph so that labels fit in?My bad, should have used
,
instead of+
. Have now fixed that.If you don't mind installing an additional package, I found
ggrepel
really useful in this scenario. You can find examples hereGreat, fixed the label with this and worked fine (x=paste0("PC1" ,percentage[1]), y= paste0("PC2" ,percentage[2])