[R] color graph in multiple plots

David Winsemius dwinsemius at comcast.net
Fri Feb 19 07:20:35 CET 2010


On Feb 19, 2010, at 12:38 AM, Roslina Zakaria wrote:

> Hi,
>
> I would like to distinguish my plots using colors but I got error  
> message.  How do I correct that?
>
>
> plot(ecdf(z), main ="CDF for observed and simulated weighted  
> sum",type="l",lwd=2,col="blue",
> xlab="Weighted sum (mm)", ylab="Cumulative Percent", xlim=c(0,15),  
> xaxs ='i', yaxs ='i',ylim=c(0,1))
> par(new=TRUE)
> plot(gen[,1],gen[,2],type="l",lwd=2,ann=FALSE,axes=FALSE,  
> col="red",xlim=c(0,15),ylim=c(0,1),xaxs ='i', yaxs ='i')
> legend(10,.2,c("obs","pre"),col=c("blue","red"),lwd=c(1,2))
>
>> plot(ecdf(z), main ="CDF for observed and simulated weighted  
>> sum",type="l",lwd=2,
> + xlab="Weighted sum (mm)", ylab="Cumulative Percent", xlim=c(0,15),  
> xaxs ='i', yaxs ='i',ylim=c(0,1))
> Error in plot.default(0, 0, type = "n", xlim = xlim, ylim = ylim,  
> xlab = xlab,  :
>   formal argument "type" matched by multiple actual arguments

Drop the type argument from the plot call. The plot.ecdf hands off to  
plot.stepfun, which is hard coded for type = "n" and then it plots  
with the segments segments function for the steps. Not much more can  
be said, since you provided neither "z" nor "gen".

-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list