I have followed the answers in https://stackoverflow.com/questions/38900698/how-to-change-labels-from-pca-using-prcomp-to-sample-names but am unable to get it to work. I have set up a dummy file (called tf4) with 7 columns and 12 rows and imported it into R Studio. The first few lines look like this
head(tf4)
# A tibble: 6 x 7
sp1 sp2 sp3 sp4 sp5 sp6 Site
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
1 1 1 1 1 1 1 A1
2 0 1 1 1 1 0 A2
3 0 1 1 1 1 1 B1
4 1 1 1 1 1 0 C1
5 0 0 1 1 0 1 D4
6 1 0 1 1 1 0 E7
I then set the row names to column 7
#setting the row names to column 7
row.names(tf4)<-tf4$Site
head(tf4)
and get a warning message
Warning message: Setting row names on a tibble is deprecated.
and when I inspect again using head(tf4) the row names have not been reset and remain as before.
But when I look at the file in R studio 'environment', it has reset the row names
snip and sketch image of the file in environment
however, when I run prcomp
model<-prcomp(tf4[,-7],scale=TRUE)
biplot(model)
the site identifiers are not used in the plot
snip and sketch view of biplot
I cannot work this out. It seems that setting the row names to column 7 is not working correctly.
Am I missing a step?
do I need an extra instruction in prcomp?
The example given by Serkan indicated where I was going wrong. It showed a rownames instruction between the prcomp and the biplot. So with my own data file I tried this
model<-prcomp(tf4[,-7],scale=TRUE)
rownames<-tf4$Site
biplot(model)
and the biplot was successfully labelled snip and sketch image of successful biplot so my conclusion is that I was setting rownames too early.