简体   繁体   中英

R - How to show points labels when plotting a matrix?

I have a simple matrix that I want to plot (X=Comp.1, Y=Comp2.). But each point has a label that I want to be shown on the plot. Here's the matrix:

        Comp.1   Comp.2
M.P.S.  0.18257  0.94809      
P.C.   -0.50166  0.27745 
Voc.   -0.55450  0.05681        
Arith.  0.63838 -0.12874 

Here's my code:

plot(myloadings,pch=16,col='blue',xlim=c(-1,1),ylim=c(-1,1))
abline(v=0)
abline(h=0)

What should I add to it ?

check the help page for ?text : text draws the strings given in the vector labels at the coordinates given by x and y. y may be missing since xy.coords(x, y) is used for construction of the coordinates.

Your data:

myloadings= data.frame(Comp.1= c(0.18, -0.5, -.55, 0.6), 
                       Comp.2=c(0.95, 0.22,0.06, -0.13))
rownames(myloadings)=c("MPS", "PC", "Voc", "Arith")

Your code:

plot(myloadings,pch=16,col='blue',xlim=c(-1,1),ylim=c(-1,1))
abline(v=0)
abline(h=0)

Plus text labels:

text(myloadings, labels=rownames(myloadings), adj=2)

情节与文本标签

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM