[R] Best way of figuring out whether graphical elements overlap?

Johannes Graumann johannes_graumann at web.de
Mon Nov 3 14:18:08 CET 2008


Thank very much for this very cool help!

Joh

Greg Snow wrote:

> There is also the spread.labs function in the TeachingDemos package that
> uses a different method from the plotrix function and should not move any
> labels that are not overlapping.  There are also the dynIdentify and
> TkIdentify functions in the same package that allow you to interactively
> move labels around to where you are happy with their positions, then
> returns the coordinates to use for the positions in a final version of the
> plot.
> 
> If you want to check by hand, you can use the strheight and strwidth
> functions to find the bounding rectangles and see if they overlap (there
> can be some cases where the actual text does not overlap even if the
> rectangles do).
> 
> Hope this helps,
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at imail.org
> 801.408.8111
> 
> 
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Johannes Graumann
>> Sent: Tuesday, October 28, 2008 8:42 AM
>> To: r-help at stat.math.ethz.ch
>> Subject: [R] Best way of figuring out whether graphical elements
>> overlap?
>>
>> Hi all,
>>
>> I'm plotting impulses, where some of them should have labels hovering
>> above them. I know of plotrix' spread.labels function, but would like
>> to save that for instances where there truely is to little space for
>> the label.
>> Does anybody have any hints what' the most efficient way might be to
>> achieve the following:
>> - plot an impulse plot
>> - before placing each of a vector of text labels, check (using
>> strhight/width), whether this collides graphically with anything
>> already plotted and only plot it if not.
>>
>> Thanks for any hints, Joh
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.



More information about the R-help mailing list