[R] 'beside' option for boxplots

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu Jun 4 13:55:20 CEST 2009


Dear Malcom,

Another option is to merge both dataset to one big dataset and then plot
the big dataset.

d1 <- data.frame(a = c(rep(1:3, each = 3)), b = c(1:9), d = "A")
d2 <- data.frame(a = c(rep(1:3, each = 3)), b = c(9:1), d = "B")
Dataset <- rbind(d1, d2)
library(ggplot2)
Dataset$a <- factor(Dataset$a)
ggplot(Dataset, aes(x = a, y = b, colour = d)) + geom_boxplot()

HTH,

Thierry

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Uwe Ligges
Verzonden: donderdag 4 juni 2009 13:45
Aan: Malcolm Ryan
CC: r-help at r-project.org
Onderwerp: Re: [R] 'beside' option for boxplots

Example:

boxplot(d1$b ~ d1$a, pars = list(boxwex = 0.15), at=c(1:3 - 0.1),
xaxt="n") boxplot(d2$b ~ d2$a, add=T, pars = list(boxwex = 0.15),
at=c(1:3 + 0.1),
xaxt="n")
axis(1, at=1:3)

Uwe

Malcolm Ryan wrote:
> Is there any way to get a boxplot of several data sets beside one 
> another on the same graph, as there is for barplot?
> 
> If I do:
> 
> d1 <- data.frame(a = c(rep(1:3, each = 3)), b = c(1:9))
> d2 <- data.frame(a = c(rep(1:3, each = 3)), b = c(9:1)) boxplot(d1$b ~

> d1$a) boxplot(d2$b ~ d2$a, add=T)
> 
> It will show the two datasets on the one graph, but the middle point 
> will overlap.
> 
> What I want is a layout more like:
> 
> barplot(t(matrix(c(d1$b, d2$b), ncol=2)), beside=T)
> 
> only showing the boxes from the plot above instead of bars.
> 
> Can this be done?
> 
> Malcolm
> 
> ______________________________________________
> 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.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.




More information about the R-help mailing list