Skip to content

How to avoid overlapping labels

2 messages · john55, Jim Lemon

#
On 02/27/2013 05:20 AM, john55 wrote:
Hi john55,
Looking at your example, it is clear that thigmophobe.labels will not 
get all of the labels right. However, it would only be necessary to 
manually change a few label positions to get it right. Say your 
coordinates are labelled "x" nd "y". First get the offsets:

textpos<-thigmophobe(x,y)

I count eight labels that need to be moved. Take the two overlapping 
labels at about x=c(-0.75,-0.55) and y=c(0.2,0.2). These two will 
probably be left overlapping by thigmophobe, probably both with a 
textpos value of 4. Change the textpos value of the leftmost label to 2. 
Then replot with thigmophobe labels using text.pos=textpos. Do the same 
for the other labels until none overlap.

If this is too much trouble, try the spread.lab function in the 
TeachingDemos package. It is a better algorithm, but not as easy to call 
as thigmophobe.

Jim