[R] How to avoid overlapping labels

Jim Lemon jim at bitwrit.com.au
Wed Feb 27 10:43:54 CET 2013


On 02/27/2013 05:20 AM, john55 wrote:
> Hi Remko,
>
> thanks for your answer. but i do
> not really understand how to use the commands.
> if i want to use  thigmophobe.labels(x,y,)   do i need to identify the xy
> coordinates for each point first and then manually move every point? and if
> i neet to do so how to use the identify() function?
> or is there any possibility to automatically place the labels in the best
> position?
>
>> MatArab<- as.matrix(ende[2:12])
>> MatArab
>> MCAArab<- mjca(MatArab, nd = 2, lambda = "JCA", maxit = 50, epsilon =
> 0.0001)
>   >plot(MCAArab, dim = c(1,2), map = "symmetric", centroids = TRUE,
>   + what = c("none", "all"), mass = c(FALSE, FALSE),
>   + contrib = c("none", "none"), col = c("#000000", "#FF0000"))
>
> <http://r.789695.n4.nabble.com/file/n4659710/lllll.jpeg>
>
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



More information about the R-help mailing list