[R] adding lines to multiple plot

Ben Bolker bolker at ufl.edu
Wed Jul 30 16:56:27 CEST 2008


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



More information about the R-help mailing list