[R] Overlay Boxplot with scatter plot

hadley wickham h.wickham at gmail.com
Tue Aug 1 15:55:55 CEST 2006


This is very easy to do with ggplot:

# you need to get the development version from http://had.co.nz/ggplot:
install.packages("ggplot", dep=TRUE, repos="http://www.ggobi.org/r/")
library(ggplot)

qplot(a, factor(b), type=c("boxplot","point"))
qplot(factor(b), a, type=c("boxplot","point"))

Regards,

Hadley

On 8/1/06, Lanre Okusanya <lanre.okusanya at gmail.com> wrote:
> my apologies about the initial bad sample code. Now assume I have
>
> a<-rnorm(6)
> b<-rep(c(10,20),each=3)
> ab<-data.frame(a,b)
>
> and I wanted to overlay this points on the graph?
>
> On 8/1/06, Petr Pikal <petr.pikal at precheza.cz> wrote:
> > Hi
> >
> > your example code is not reproducible.
> >
> > On 1 Aug 2006 at 8:09, Lanre Okusanya wrote:
> >
> > Date sent:              Tue, 1 Aug 2006 08:09:38 -0400
> > From:                   "Lanre Okusanya" <lanre.okusanya at gmail.com>
> > To:                     R-help at stat.math.ethz.ch
> > Subject:                [R] Overlay Boxplot with scatter plot
> >
> > > I am trying to make a box plot and overlay it with a scatter plot from
> > > another data.frame. I was able to successfully create the boxplot, but
> > > when i tried using points(x~y...) the dots did not show up.
> > >
> > > example code
> > >
> > > aa<-(300,300,300,300,600,600,600,600,900,900,900,900)
> >          ^^^ missing c
> > > bb<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56)
> > > cc<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56)
> > > nn<-data.frame(aa,bb)
> > different length of aa and bb
> >
> > > mm<-data.frame(aa,cc)
> > > boxplot(bb~aa, data=nn)
> > > lines(cc~aa, data=cc)
> > >
> > > Any help with example code is appreciated.
> >
> > x<-rnorm(20)
> > y<-rep(c(10,20),each=10)
> > bbb<-boxplot(x~as.factor(y))
> >
> > although it seems as boxes are drawn at 10, 20 they are not.
> > Actually the x position of each box is located at
> >
> > - from help page -
> > at              numeric vector giving the locations where the boxplots should be
> > drawn, particularly when add = TRUE; defaults to 1:n where n is the
> > number of boxes.
> >
> > as you can clearly demonstrate by issuing
> >
> > points(1,0, cex=10)
> >
> > HTH
> > Petr
> >
> > >
> > > Thank you.
> > >
> > > Lanre
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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.
> >
> > Petr Pikal
> > petr.pikal at precheza.cz
> >
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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