Question

I am playing with RGooglemaps, and have been able to plot lines on a map. I loaded my lats and longs from a csv into a coords object.

I wanted to imply direction using: PlotArrowsOnStaticMap

defined as:

    PlotArrowsOnStaticMap(MyMap, lat0, lon0, lat1 = lat0, lon1 = lon0, TrueProj = TRUE, FUN = arrows, add = FALSE, verbose = 1,...)

I define lat0 as something like coords[,'lat']. How do I give the lat1?

The value is the next row in the file - but how do I describle that relatively? (coords[+1,'lat'] in pseudocode.

Is there some basic reading I should be doing?

Was it helpful?

Solution

An inelegant work around is to create new columns for your lat and long that are upshifted by one row compared to the initial rows. The value of the first row is wrapped to the bottom (or replaced by NA if this does not make sense).

coords$lat.1<-coords$lat[c(2:length(coords$lat), 1)]
coords$lon.1<-coords$lon[c(2:length(coords$lon), 1)]

You now have two columns for lat (lat and lat1) and two columns for long (lon, lon1).

with(coords, PlotArrowsOnStaticMap(lat0=lat, lon0=lon, lat1=lat1, lon1=lon1...)

OTHER TIPS

Some of the functions commonly used to do this include head, tail, and embed:

> tmp <- 1:10
> cbind( head(tmp,-1), tail(tmp,-1) )
      [,1] [,2]
 [1,]    1    2
 [2,]    2    3
 [3,]    3    4
 [4,]    4    5
 [5,]    5    6
 [6,]    6    7
 [7,]    7    8
 [8,]    8    9
 [9,]    9   10
> embed(tmp, 2)
      [,1] [,2]
 [1,]    2    1
 [2,]    3    2
 [3,]    4    3
 [4,]    5    4
 [5,]    6    5
 [6,]    7    6
 [7,]    8    7
 [8,]    9    8
 [9,]   10    9
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top