Reputation: 3781
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 ?
Upvotes: 0
Views: 980
Reputation: 6532
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)
Upvotes: 2