Re: [R] adding lines to multiple plot

From: Ben Bolker <bolker_at_ufl.edu>
Date: Wed, 30 Jul 2008 14:56:27 +0000 (UTC)

Gary W <g.watmough <at> gmail.com> writes:

>
>
> Hi ben
>
> Thanks for that, the density lines have now worked, however i was hoping
> that the labels would be the names of the columns in my original data set
> not numeric. any advice how to do this?
>
> gary w
>

mapply(function(v,n) {

    hist(v,prob=TRUE,main=paste("Histogram of",n),xlab=n)

       lines(density(v),lwd=2)
      },
      variables,
      variablenames)

  Or the loop equivalent.

  There are also slick ways of doing this with the lattice package (and getting a nice one-page layout of your graphs), if you "melt" your data frame first with the command from the reshape package.

  Ben Bolker



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 Wed 30 Jul 2008 - 14:58:36 GMT

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 Wed 30 Jul 2008 - 16:32:55 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