0

I am trying to add inset of my polygon into a map.

Page 11 of this pdf (https://journal.r-project.org/archive/2013-1/kahle-wickham.pdf) shows what im trying to get. Unfortunately I am new in R and can`t understand how it works even with this example... In my case it shows up this error: Error in f(...) : could not find function "viewport" which I dont understand. My code

swd <- read.csv2("C:/MapyR/rozmieszczenieswd/swdwsp.csv",header= TRUE, sep = ";", encoding = "unknow") 
swd$Lat <- as.numeric((strtrim(swd$Lat,8)))
swd$Long <- as.numeric((strtrim(swd$Long,8)))

polska <- get_map(
  location=c("Olsztyn"), 
  zoom=12, 
  maptype="roadmap" 

)    

olsztyn <- subset(swd, Lat>=53.72 & Lat<= 53.84 & Long>=20.40 & Long<=20.55,select = rodzaj:Long)

mapa <- ggmap(polska, extent = "device", legend ="bottomright") 
  punkty <-  stat_density_2d( aes(x=Long,y=Lat,fill= ..level..,alpha=..level..)
                                 ,data=olsztyn
                                 ,size=2 
                                 ,geom = "polygon"
  )

nowa <- mapa +   inset(
     grob = ggplotGrob(ggplot()+punkty + theme_inset()),
    xmin = 20.50, xmax = 20.55, ymin = 53.72, ymax = 53.76 #I tryed many versions of x,y 
   ) 


sciezka <- file.path("C:","MapyR","proby density",paste("inset",".png"), sep="")
png(file=sciezka, width = 2500 , height=1567)
print(nowa) 
dev.off()

This is how far I can get with my code, Still I cant add this inset:

banshe
  • 75
  • 2
  • 9
  • 1
    I find this example quite difficult to follow as there is no way we could attempt to reproduce it. Let me clarify a few things; so you have your map *(mapa)* what is the thing you want to add to it? Could you maybe attempt to reproduce an example with some data we could use? – Konrad Feb 17 '16 at 09:46
  • Hadley's R Journal example tosses `Error in grid.Call.graphics(L_setviewport, vp, TRUE) : non-finite location and/or size for viewport` now (probably due to the massive update to the ggplot2 ecosystem). You may want to find a different approach. – hrbrmstr Feb 17 '16 at 11:07
  • hmm thats explain my problems... – banshe Feb 17 '16 at 13:53

0 Answers0