eliza botto
2012-Sep-21 23:11 UTC
[R] efficient overlapping average curve on original curves
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? thanks in advance for you time. eliza botto [[alternative HTML version deleted]]
Rui Barradas
2012-Sep-21 23:33 UTC
[R] efficient overlapping average curve on original curves
Hello, Something like this? # Make up some data mat <- matrix(rnorm(100*37), ncol = 37) mat <- apply(mat, 2, cumsum) avg <- rowMeans(mat) # matplot - matrix plot matplot(mat, type = "l") lines(avg, lwd = 2) I've also seen some very nice graphics for ploting many lines in ggplot2 using transparency in order to give a visual picture of where there are more lines. Hope this helps, Rui Barradas Em 22-09-2012 00:11, eliza botto escreveu:> 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? > thanks in advance for you time. > > eliza botto > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
David Winsemius
2012-Sep-22 01:09 UTC
[R] efficient overlapping average curve on original curves
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