Skip to content
Advertisement

Loading a raster data of map PNG on ggmaps of R

This will be cross posted on R’s mailing list.

I have the map as a png, so I won’t be using the get_map function. I have extracted the raster data from the png, and I wish to load the map as it is on the display of R, and then I would like to plot a point on it.

So, here’s the way I have tried ggmaps. The program is compiling fine. Problem here is that there isn’t any output being shown.

JavaScript

Of course I am doing something wrong. Please point out.

JavaScript

EDIT: I have found an error. Actually I was first running it with source (uff.R), and this command didn’t show any error. Then I tried Rscript.

JavaScript

Advertisement

Answer

Your ggimage is failing because there’s no x and y in it. Rename your lat-long coords to x and y. Here is a completely reproducible example. This is basic ggplot stuff:

JavaScript

Run those commands on your command line and you should see a plot. Possible reasons for failing are:

  • Your R doesn’t have an X11 connection to your display. Is this all running on a local Linux machine? You haven’t connected to a server? If R can’t pop up a graphics window it will probably try and create an Rplots.pdf file.
  • You are running in a script which isn’t printing. Wrap all ggplot, grid, and lattice graphics functions that you want to produce output in print() function calls. This is a FAQ, I think. Paul Hiemstra put this as an answer but then deleted it…
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement