[R] how to avoid grid overlapping in a boxplot

Rui Barradas rui1174 at sapo.pt
Thu Mar 22 21:00:04 CET 2012


Hello,


Michael Weylandt wrote
> 
> It's a bit of a hack, but you could just redraw the boxplot on top of
> the grid lines:
> 
> x <- rnorm(50)
> boxplot(x)
> grid()
> boxplot(x, add = TRUE)
> 
> Michael
> 
> 
> On Thu, Mar 22, 2012 at 12:08 PM, maxbre <mbressan at .veneto> wrote:
>> Given the following chart: i.e. a boxplot with a grid
>>
>> boxplot(x~y)
>> grid(nx=NA,ny=NULL)
>>
>> my question: how to avoid the overlapping of boxes (and whiskers) by grid
>> lines?
>>
>> thank you for any help pointing me in the right direction
>>
>> max
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/how-to-avoid-grid-overlapping-in-a-boxplot-tp4495955p4495955.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help@ 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@ 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.
> 


Doesn't remove the grid lines, you need the parameter 'col':

x <- rnorm(50)
boxplot(x)
grid()
boxplot(x, add = TRUE, col="white") 

or, start an empty plot, draw the grid then the boxplot:


plot(1, type="n", xlim=c(0.5, 1.5), ylim=range(x), xlab="", ylab="",
axes=FALSE)
grid() 
boxplot(x, add=TRUE, col="white")

If you have two groups, the xlim would be c(0.5, 2.5), etc...

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/how-to-avoid-grid-overlapping-in-a-boxplot-tp4495955p4496688.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list