0

I am trying to plot polygon data using ggmap, but the system crashes, not sure why. My area dataframe looks like this:

> head(area)
      long     lat order  hole piece id group
1 190393.2 5794527     1 FALSE     1  0   0.1
2 190474.4 5794516     2 FALSE     1  0   0.1
3 190573.0 5794533     3 FALSE     1  0   0.1
4 190619.4 5794580     4 FALSE     1  0   0.1
5 190619.4 5794620     5 FALSE     1  0   0.1
6 190619.4 5794661     6 FALSE     1  0   0.1

I get a map as the base layer:

chile <- get_map(location = "Chile", zoom = 6, maptype = "toner", source = "stamen")

And now I plot it:

ggmap(chile, base_layer = ggplot(data = area, aes(long, lat))) +
  geom_path(aes(color = id))

I have tried this code many time and it takes forever and eventually crashes. Ideas on what is going on?

NBK
  • 887
  • 9
  • 20
  • Those coordinates are not long/lat (which would be between -180 and 90, and -90 and 90 respectively). You'll need to transform those coordinates into long/lat before working with google/osm maps. Where do the coords come from? – Phil Apr 12 '19 at 18:51
  • Hi Phil, thanks for the comment. I had not notice the range. The data comes from a shapefile from this link: https://www.bcn.cl/siit/obtienearchivo?id=repositorio/10221/10396/1/division_comunal.zip – NBK Apr 12 '19 at 19:02
  • It is official data from the Chilean government, so I assume it is correct. Do you know what the numbers under long/lat may be expressing? – NBK Apr 12 '19 at 19:03
  • It's in EPSG 32719 so you need to transform it then plot it with your ggmap object. This post walks you through it https://stackoverflow.com/questions/47749078/how-to-put-a-geom-sf-produced-map-on-top-of-a-ggmap-produced-raster – Phil Apr 12 '19 at 20:06

0 Answers0