# [R] Vertical boxplot with a continuous X axis

Bert Gunter bgunter.4567 at gmail.com
Fri Feb 24 08:01:36 CET 2017

```Sebastien:

The linked post is unclear: two of the rows have the same age, so
should there be 10 boxplots for the 10 rows or 9 for the 9 different
ages? I assumed the latter, as otherwise how could one disciminate
rows with the same age that have overlapping values?

For lattice, I just used age as the group= parameter to group by ages
and used panel.bwplot for the panel.groups function. My "aesthetics"
are different than shown in the linked post, but can be altered in
lattice through the panel.bwplot and par.settings parameters as
described in ?panel.bwplot:

y <- unlist(df[,-11])
age <- rep(df[,"age"],10) ## Could be done programatically
xyplot(y~age, groups = age,
panel = function(...){
panel.abline(h = seq(40,65, by=5),
v = seq(30,70, by =5),
col="lightgray")
panel.superpose(...)
},
panel.groups = function(x,y,...)
panel.bwplot(x,y,horiz=FALSE,fill = "lightgray",
pch = 16, cex=.7,col= "black",box.width = 1.5),
par.settings =list(box.rectangle = list(col="black"))
)

However, note that this too could produce a hopeless mishmosh if the
ages are close together so that the boxplots overlap; or you could end
up getting nearly invisible skinny boxes, as in the plot shown in the
linked post.  So on the whole, I think you are better off treating the
ages as a factor and thereby separating them, e.g.

bwplot(y~age, fill = "lightgray", horiz = FALSE,
panel = function(...){
panel.abline(h = seq(40,65, by=5),col="lightgray")
panel.bwplot(...)
},
scales = list(x= list(lab = sort(unique(age)))),
par.settings =list(box.rectangle = list(col="black"))
)

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Thu, Feb 23, 2017 at 8:52 PM, Sebastien Bihorel
<sebastien.bihorel at cognigencorp.com> wrote:
>
> Hi,
>
> Can the boxplot design illustrated in the post (http://stackoverflow.com/questions/39849459/how-to-create-boxplots-with-a-continuous-x-axis-in-r) be reproduced with lattice or a lattice-derived function?
>
> Thank you
>
> Sebastien
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

```