Domanda

I'd like to create a biplot for a prcomp primary component analysis. However, since I have lots of rows in my matrix, I don't want to print all these labels. I'm mostly concerned in the overall distribution, not in all the details. So I'd like to only represent the data points as dots, without labels. How can I do this?

Right now I do something like this:

biplot(prcomp(data, scale.=T), xlabs=rep(".", nrow(data)))

But I'm concerned that this is using the character '.' which will be located at the baseline of the text, and as such a slight way off from where the point is actually supposed to be, thus giving an overall shifted appearance. Is this concern justified? How can this be avoided? Is there a simpler alternative?

Bonus points for any solution which labels outliers far from the center of the diagram, in addition to dots everywhere. But that does sound tricky.

Looking at stats:::biplot.default, and how it calls plot(x, type = "n", …), it might well be that plotting the points themselves is not intended, so I fear that what I'm asking for might even be impossible. But perhaps there is a trick of some kind to work around this.

È stato utile?

Soluzione

I think your "." will be centered vertically, rather than shifted to the bottom (which I think is what you were concerned about?)

comparing different xlabs:

set.seed(123) #thanks to MvG for spotting
data = cbind(rnorm(25), rnorm(25), rnorm(25))
biplot(prcomp(data, scale.=T), xlabs=rep(".", nrow(data))) #your code
X11()
biplot(prcomp(data, scale.=T), xlabs=rep("·", nrow(data))) #"middle dot"
X11()
biplot(prcomp(data, scale.=T), xlabs=rep("˙", nrow(data))) #"dot above"
X11()
biplot(prcomp(data, scale.=T), xlabs=rep(".·˙", nrow(data))) #all three
X11()
biplot(prcomp(data, scale.=T), xlabs=rep("I", nrow(data)))

To me (R-3.0.1 on Win7) it looks like the plot takes the size/shape of the character(s) into account, as the three single dot examples are virtually identical despite their relative vertical positioning, and all appear in the middle of where the "I"s are plotted.

If you understand how the biplotted values are produced from the prcomp output (I don't):

str(prcomp(data, scale.=T)

You could make a blank biplot with

xlabs=rep("", nrow(data))

and add to it with points() made manually, but I think it would look the same. Your xlab is also not limited to using what you can see on your keyboard as you can use all kinds of special characters, e.g. ■●▲

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top