Re: [R] text overlap in plot

From: Peter Ehlers <ehlers_at_ucalgary.ca>
Date: Fri, 24 Jun 2011 08:46:44 -0700

On 2011-06-24 08:00, David Winsemius wrote:
>
> On Jun 24, 2011, at 10:07 AM, David martin wrote:
>
>> Hey,
>> Here is a snippet that generated a boxplot and separates points so
>> that they do not overlap. I have a problem to avoir text
>> overlapping. Any help would be helpful.
>>
>>>
>> attach(InsectSprays)
>> boxplot(count ~ spray, data = InsectSprays, outpch = NA)
>> stripchart(count ~ spray, data = InsectSprays,
>> vertical = TRUE, method = "jitter",
>> pch = 21, col = "maroon", bg = "bisque",
>> add = TRUE)
>>
>> text(count ~ spray , row.names(InsectSprays), pos=4,cex=0.6)
>> detach(InsectSprays)
>
> Throws an error on my machine. I do not think text has a formula method.

It does now; see the bottom of ?text.
But the command requires that row.names(....) be identified as the "labels" argument. As it stands, the positional interpretation of row.names(....) makes it the "data" argument.

And it would be better to use the "data" argument than to attach/detach.

Peter Ehlers

>
> This gets part of the way there using the spreadout function in
> plotrix, but it apparently needs to be set up so that it only gets
> applied within each category:
>
> require(plotrix)
> with(InsectSprays, text(spray, spreadout(count,
> 0.3),labels=rownames(InsectSprays), pos=4, cex=0.5) )
>
> So, since InsectSprays is sorted by 'spray', and spreadout preserves
> the order of its arguments, using tapply should not mess up the order:
>
> with(InsectSprays, text(spray,
> unlist( tapply(InsectSprays$count, InsectSprays$spray,
> spreadout, mindist=0.2) ) ,
> labels=rownames(InsectSprays), pos=4, cex=0.5) )
>
> Seems pretty close.



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. Received on Fri 24 Jun 2011 - 15:49:40 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 24 Jun 2011 - 16:10:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive