Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Non-overlapping scatter mlabels


From   <[email protected]>
To   <[email protected]>
Subject   Re: st: Non-overlapping scatter mlabels
Date   Wed, 28 Aug 2013 09:44:38 +0200

Yesterday my email to statalist bounced back due to unknown reasons so I'll give it another try.


Nick cox pointed out Ulrich Kohlers mlabvpos function for -egenmore- which indeed is a nice idea to optimize marker label positioning in scatterplots. Thanks!

***

But since the -egenmore-function doesn't control for overlaps I fiddled around with some ideas by myself. 
The one I worked with was to create a virtual box around every label.
I used the x/y-coordinates of the marker, the given mlabvpos-value, the length of the label, the mlabsize-value and the x and y ranges to calculate the coordinates of the virtual box.
At the moment only by rule of thumb and only for linear scaling.

With two nested loops each pair of markers is checked for overlaps of their virtual boxes. 
In case of an overlap the mlabvpos-value of one marker is randomly reassigned, after that, the virtual boxes are recalculated.

Both nested loops are inside a -while- loop that stops when there are no overlaps left or a maximum of runs (e.g. 100) is reached.
This trial-and-error process has a good chance to remove overlaps if there is some empty space around the overlapping labels.
With scarce space chances are rather low. 

The best way would be to analyze the plot region for free and occupied space and find some global optimal distribution for marker labels. 
But this seems rather difficult.

Best wishes

Stefan Gawrich
Dillenburg
Germany










*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index