xyzzyrz
xyzzyrz

Reputation: 16396

How to cleanly label the points in a simple ggplot2 scatterplot?

See the examples from http://had.co.nz/ggplot2/geom_text.html; they're pretty terrible. Labels overlap each other, run outside the plot, etc.

I thought directlabels might help, but it doesn't really:

direct.label(qplot(wt,mpg,data=mtcars,colour=rownames(mtcars)))

Manually positioning each label is tedious. Hoping there's something that makes labels a bit more usable. Anything that might fit the bill?

Upvotes: 7

Views: 1220

Answers (1)

Tomas
Tomas

Reputation: 59435

hope it's not too late for the answer. I don't now about ggplot2, I used normal scatterplots using plot(). I tried many labelling algorithms, and the best was pointLabel() from package maptools with wrapping the labels by spaces :-)

pointLabel(x, y, labels = paste("  ", point_names, "  ", sep="")

I tried thigmophobe.labels() from package plotrix, textxy() from package calibrate or standard text(), but I think pointLabel() was best.

But anyway for my purpose I ended up to simply use identify() and I just clicked the points for which I wanted the label - very useful, you just click the outliers and some interesting points that's it!!

Tomas

Upvotes: 1

Related Questions