The question has long been spinning in my head until the need arose. The following data is available:
enter image description here

I biplot :
enter image description here

It is necessary that instead of the observation number, he wrote the name of the city. In all embedded data, these names already exist and this problem does not arise. Is it possible to indicate that city is not just one of the variables, but the identifier (name) of each observation?

  • one
    Please do not insert screenshots of the data in the questions. Use the dput() function to generate sample data. Example: dput(head(mtcars)) . - Artem Klevtsov

3 answers 3

You must specify rownames row rownames :

 rownames(data) <- data$city 

    When loading data using read.table , read.csv or read.delim you can specify the argument row.names=1 , i.e. use the first column as a string name, for example:

     cities<-read.delim("~/города.txt", row.names=1) 

      It is not necessary to use the default biplot.procmp() . You can explicitly pass a parameter to the more general biplot() function using the parameter xlabs=вектор_имен .

      In the case described:

       biplot(prcomp(pca[,-1]), xlabs=pca[,1])