Hi, I have several data sets which are all approximately within the same values as each other (both X and Y) and all of these data sets more or less overlap each other when plotted on the same graph. However, although each data set varies between approximately the same range, there are vastly different numbers of data points within each data set (due to the nature of how these values had to be measured). Currently, I am trying to figure out a way to produce a graph showing all these data sets and a line showing the average of all of the data sets. Given the different number of data points, I can't think of an easy way to do this. Can anybody help? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Average-of-several-line-plots-tp3254850p3254850.html Sent from the R help mailing list archive at Nabble.com.
On 2011-02-02 08:44, mattnixon wrote:> > Hi, > > I have several data sets which are all approximately within the same values > as each other (both X and Y) and all of these data sets more or less overlap > each other when plotted on the same graph. However, although each data set > varies between approximately the same range, there are vastly different > numbers of data points within each data set (due to the nature of how these > values had to be measured). > > Currently, I am trying to figure out a way to produce a graph showing all > these data sets and a line showing the average of all of the data sets. > Given the different number of data points, I can't think of an easy way to > do this.Have a look at ?approxfun Peter Ehlers> > Can anybody help? > > Thanks!
It is not clear from your message whether these data represent functions or such. Could you perhaps bring up an example? I'm guessing each data set contains evaluation points and function values at those points, and that you would like to plot these functions and the mean function all on the same graph, is that right? If the points in the domain differ from each other, it's not as immediate to build a mean function. A quick recipe would be to use splinefun on each data set, generate a new grid for the domain, evaluate each obtained spline on this grid to get new data sets and build the mean function from there. But without an example it's really just guessing. Hope this helps anyway. ?splinefun Best regards, Eduardo On Wed, Feb 2, 2011 at 2:44 PM, mattnixon <m.r.nixon at ex.ac.uk> wrote:> > Hi, > > I have several data sets which are all approximately within the same values > as each other (both X and Y) and all of these data sets more or less overlap > each other when plotted on the same graph. However, although each data set > varies between approximately the same range, there are vastly different > numbers of data points within each data set (due to the nature of how these > values had to be measured). > > Currently, I am trying to figure out a way to produce a graph showing all > these data sets and a line showing the average of all of the data sets. > Given the different number of data points, I can't think of an easy way to > do this. > > Can anybody help? > > Thanks! > -- > View this message in context: http://r.789695.n4.nabble.com/Average-of-several-line-plots-tp3254850p3254850.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. >
Hi, Peter: thank you, I have taken a look at ?approxfun but I'm not sure it does what I'm after. Eduardo: The data doesn't represent functions. Basically the X values represent the distance across a sample and the Y values are a measure of the colour intensity at that point across the sample (i.e. a line plot across the sample). Each data set represents a measurement across a different section of the sample. All data sets show alternating 'light' and 'dark' sections, though the sample isn't perfect so the widths of each section do not entirely match up from one data set to another. The problem comes from the fact that some data sets contain as many as 400 measurements across the sample whereas others contain as few as 150 measurements. This means that measurements do not necessarily occur at the same value of X on different data sets. Therefore I think I need some way to average the lines ('of best fit') that each data set creates on the graph, rather than averaging the data ponits themselfs as I can't see how I can take averages/weighted averages of the data points when they occur at different values of X (and at different intervals) across the sample. Is my description any better this time? -- View this message in context: http://r.789695.n4.nabble.com/Average-of-several-line-plots-tp3254850p3257696.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- Storage of byte code-compiled functions in sysdata.rda
- Storage of byte code-compiled functions in sysdata.rda
- RFC: spline / splinefun (etc) amalgamation
- lookup function for density(...) objects
- Connect observed values by a smooth curve, is there any method to get coordinate value of arbitrary point on the curve?