[R] efficient overlapping average curve on original curves

David Winsemius dwinsemius at comcast.net
Sat Sep 22 03:09:05 CEST 2012


On Sep 21, 2012, at 4:11 PM, eliza botto wrote:

> 
> Dear useRs,
> 
> my question could be very basic for which i apologize in advance. 
> Each column of a matrix with dimensions 365 rows and 37 columns was drawn against another matrix of dimensions 365 rows and 1 column. with that i was able to draw 37 curves on the same axis. 
> now i want to draw an average curve of these 37 curves on the same axis in such a way that all the curves (average and 37 curves) should appear on the same axis at the same time. 
> i used
> 
>> par(new=TRUE)
> 
> But it has 2 limitations
> 
> 1- it completly distorted y-axis values
> 2- it was not very efficient as average curve in no overlapped the original curves.
> 
> can any1 advise me what to do?

If you are going to use par(new=TRUE) you must make sure your 'xlim' and 'ylim' are the same in the second plot as in the original plot. In your misadventure, the ylim for the means was probably much more narrow than in the original data. Or to do it easily, follow Rui Barradas' advice.

Or you could `rbind` the `rowMeans` to the original data before using `matplot`.
Perhaps:

matplot(x=mat1, y= rbind(mat2, rowMeans(mat2) ) )

-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list