0

I'm trying to take a data frame:

lat         lng       active
122.536226 37.86047    green
122.536422 37.860303   green
122.536688 37.860072   red
...

and create a map, using RgoogleMaps, with line segments (or lines?) that are from row 1 to row 2, with the color in the 'active' column. My map just shows green and I'm not sure why. Here's the code I've written:

center <- c(mean(all_lat,na.rm=TRUE), mean(all_lng,na.rm=TRUE))
latRange = range(c(all_lat),finite=TRUE)
lngRange = range(c(all_lng),na.rm=TRUE, finite=TRUE)
zoom <- min(MaxZoom(latRange,lngRange))
mymap <- GetMap(center=center, zoom=zoom)

# show the basic map
PlotOnStaticMap(mymap,lat=c(mean(all_lat)),lon=c(mean(all_lng)), cex=0.5)

# add line segments
PlotOnStaticMap(mymap,lat=segs$lat,lon=segs$lng,col=segs$active,   
  FUN=lines,add=TRUE)

Suggestions?

amracel
  • 323
  • 1
  • 11
  • Maybe your `active` column is a factor? Try using `stringsAsFactors = FALSE` when reading/creating the data frame. – Molx Mar 31 '15 at 15:20
  • No, I don't think so. If it was, I wouldn't be able to pull any colors - it would all be black by default, wouldn't it? – amracel Mar 31 '15 at 17:10
  • That's correct. By the way, this is probably not your case, but, using only the three rows above you only get green, since you don't have a forth row to connect to the third and paint red. I just though I'd comment that because it happened when I tried your code (using `segments` on a simple plot). – Molx Mar 31 '15 at 18:02

0 Answers0