Skip to content
Prev 278139 / 398502 Next

Binned line plot

On 11/22/2011 04:29 PM, Jeffrey Joh wrote:
Hi Jeffrey,
There are three possibilities that come to mind:

1) You want to bin the points based on their order in the data frame.

2) You want to bin the points based on the x or y values of the coordinates.

3) You want to bin the points based on the x _and_ y values of the 
coordinates.

Number 1 is trivial and has already been answered (assume a two column 
data frame of coordinates named "xypoints").

#first point - set up a loop to get a vector of averages
meanx<-rep(0,200)
meany<-rep(0,200)
for(index in 1:200) {
  start<-1+50*(index-1)
  meanx[index]<-mean(xypoints[start:(start+49),"x"])
  meany[index]<-mean(xypoints[start:(start+49),"y"])
}
plot(meanx,meany,type="l")

Number 2 requires that you sort the pairs based on the value of the one 
you want, then apply the same process as 1 to the sorted pairs. Number 3 
is somewhat more difficult.

I don't do this much, and some of the people who do map analysis will 
probably come up with a much better method.

Find the most extreme point.
Find the 49 points closest to that point to constitute group 1.
Remove those points from the data frame.
Go back to the first step if there are any points left.

You will end up with 200 groups of points that are spatially grouped. 
Get the centroids and plot as above.

Another wild guess from

Jim