Dots instead of labels for biplot.prcomp

10,370

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. ■●▲

Share:
10,370
MvG
Author by

MvG

Dr. Martin von Gagern. Studied computer sciences, obtained a PhD in mathematics, currently a Google site reliability engineer.

Updated on June 04, 2022

Comments

  • MvG
    MvG almost 2 years

    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.

  • MvG
    MvG about 10 years
    Nice answer. Simply testing whether my concern is valid seems so obvious in hindsight, but I hadn't known about how to open multiple windows, and that's essential for comparing the results. Adding points later on sounds like an interesting idea, but would entail duplicating large parts of biplot.prcomp, all that computation of lam. I'm not sure whether set.seed=123 makes sense; I guess that should be set.seed(123). It's a function, not a variable.