3

I'm using the package RgoogleMaps for R. I've plotted my map, and i need to add points with points command, but it doesn't work. Here's my code:

PlotOnStaticMap(Map, add = FALSE, TrueProj=F,  FUN = points)    # plot the background

# add external boundary

for (nb in 1:100)
{
    points(x[nb],y[nb],type="l",lwd=3)
}

How could I fix it?

Hack-R
  • 22,422
  • 14
  • 75
  • 131
Darko
  • 1,448
  • 4
  • 27
  • 44
  • 1
    I may be able to help, but can you make this reproducible by invoking a built in dataset to use as an example? Also, I submitted a minor edit to your question because packages are case-sensitive, so you have to type it exactly right: `RgoogleMaps` – Hack-R Dec 08 '14 at 14:49

1 Answers1

4

I think this is what you're looking for:

lat = c(40.702147,40.718217,40.711614);
lon = c(-74.012318,-74.015794,-73.998284);
center = c(mean(lat), mean(lon));
zoom <- min(MaxZoom(range(lat), range(lon)));


Map <- GetMap(center=center, zoom=zoom,markers = paste0("&markers=color:blue|label:S|",                                                      
                                                          "40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=",
                                                          "color:red|color:red|label:C|40.718217,-73.998284"), destfile = "MyTile1.png");





tmp <- PlotOnStaticMap(Map, lat = c(40.702147,40.711614,40.718217), 
                       lon = c(-74.015794,-74.012318,-73.998284), 
                       destfile = "MyTile1.png", cex=1.5,pch=20,                       
                       col=c('red', 'blue', 'green'), add=FALSE);


# Now let's add points with the points method:

PlotOnStaticMap(Map, lat = c(40.702147,40.711614,40.718217), 
                lon = c(-74.015794,-74.012318,-73.998284), 
                lwd=1.5,col=c('red', 'blue', 'green'),  points(x = 40.702148, y = NULL ), add=TRUE)

See the syntax for points() within PlotOnStaticMap?

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • Perfect. Do you also know how to add the result of `image` command to `PlotOnStaticMap`? – Darko Dec 08 '14 at 16:10
  • @Darko Glad that was helpful. I'm not sure offhand but I believe that you can find the answer to that here: http://www.klshu.com/wp-content/uploads/2014/03/R-Graph-Cookbook.pdf – Hack-R Dec 08 '14 at 19:10
  • i didn't found the answer about image command. I will post it as a new answer, because it's different – Darko Dec 09 '14 at 15:39
  • @Darko Good idea. I mentioned the link above because it was a Google search result when I search on `PlotOnStaticMap` and `image command` but I guess the context was different; sorry about that. – Hack-R Dec 09 '14 at 17:28