Re: [R] adding lines to multiple plot

From: Gary W <g.watmough_at_gmail.com>
Date: Wed, 30 Jul 2008 07:24:53 -0700 (PDT)

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

Ben Bolker wrote:
>

>> 
>> ##find unique column names in table 
>> variablenames<-unique(names(variables)) 
>> ## define number of unique names 
>> Nvariables<-length(variablenames) 
>> for(i in 1:Nvariables){ 
>> par(mfrow=c(1,1),ask=TRUE) 
>> } 

>
> previous loop is a little weird -- it has exactly the
> same result as just running the command inside once.
>
> Labeling with the numeric values is a bit of a pain.
> If you don't need them you can just do
>
> lapply(variables,
> function(v) {
> hist(v,prob=TRUE)
> lines(density(v),lwd=2)
> })
>
> If you need the labels you can either do
>
> mapply(function(v,i) {
> hist(v,prob=TRUE,main=paste("Histogram of",i),xlab=i)
> lines(density(v),lwd=2)
> },
> variables,
> 1:Nvariables)
>
> Or it might be easier to just do the whole thing with
> a for loop:
>
> for (i in 1:Nvariables) {
> hist(variables[[i]],prob=TRUE,main=paste("Histogram of",i),xlab=i)
> lines(density(variables[[i]]),lwd=2)
> }
>
> 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.
>
>
-- 
View this message in context: http://www.nabble.com/adding-lines-to-multiple-plot-tp18732850p18734458.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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:34:26 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 - 15:32:58 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