mdsumner / ggpolypath

Polygons with holes for ggplot2
https://mdsumner.github.io/ggpolypath/
17 stars 1 forks source link

geom_polypath doesn't play nicely with ggmap defaults #4

Open luke-a opened 7 years ago

luke-a commented 7 years ago

Here's an example (from stackoverflow):

library(mapdata)
library(ggmap)
library(ggplot2)
library(raster)
library(ggpolypath)
Peru <- get_map(location = "Peru", zoom = 5, maptype="satellite") 
data(wrld_simpl, package = "maptools")
polygonMask <- subset(wrld_simpl, NAME=="Peru")
bb <- unlist(attr(Peru, "bb"))
coords <- cbind(
  bb[c(2,2,4,4)],
  bb[c(1,3,3,1)])
sp <- SpatialPolygons(
  list(Polygons(list(Polygon(coords)), "id")), 
  proj4string = CRS(proj4string(polygonMask)))
sp_diff <- erase(sp, polygonMask)
sp_diff_df <- fortify(sp_diff)  
pp <- list(  
  geom_polypath(
    aes(long,lat,group=group),
    sp_diff_df, 
    fill="white",
    alpha=.7
  ))

## Default extent="panel" throws an error:
ggmap(Peru) + pp
# Error in grid.Call.graphics(L_path, x$x, x$y, index, switch(x$rule, winding = 1L,  : 
#   unendliches x oder y im Grafikpfad

ggmap(Peru,extent="device") + pp
# Error in grid.Call.graphics(L_path, x$x, x$y, index, switch(x$rule, winding = 1L,  : 
#   unendliches x oder y im Grafikpfad
# In addition: Warning message:
# `panel.margin` is deprecated. Please use `panel.spacing` property instead 

ggmap(Peru,extent="normal") + pp
## works

My session info:


sessionInfo()
# R version 3.3.2 (2016-10-31)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 7 x64 (build 7601) Service Pack 1
# 
# locale:
# [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
# [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
# [5] LC_TIME=German_Germany.1252    
# 
# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
# [1] ggpolypath_0.1.0 raster_2.5-8     sp_1.2-4         ggmap_2.6.1      ggplot2_2.2.1   
# [6] mapdata_2.2-6    maps_3.1.1      
# 
# loaded via a namespace (and not attached):
#  [1] Rcpp_0.12.10        magrittr_1.5        munsell_0.4.3       colorspace_1.3-2   
#  [5] geosphere_1.5-5     lattice_0.20-34     rjson_0.2.15        jpeg_0.1-8         
#  [9] rlang_0.0.0.9018    stringr_1.1.0       plyr_1.8.4          tools_3.3.2        
# [13] rgdal_1.2-5         grid_3.3.2          gtable_0.2.0        png_0.1-7          
# [17] rgeos_0.3-22        digest_0.6.12       lazyeval_0.2.0.9000 tibble_1.3.0.9002  
# [21] mapproj_1.2-4       reshape2_1.4.2      labeling_0.3        stringi_1.1.2      
# [25] RgoogleMaps_1.4.1   scales_0.4.1.9000   proto_1.0.0