Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Saving large leaflet map file as pdf (or another sharp format) [R]

$
0
0

I would like to ask if there is any convenient way how to save leaflet map as pdf when it is very large file. I am aware of saveWidget that allows to save as pdf, however when map is very large it tend to be very slow.

Is there a way how one could save example map that I created in PDF (or any other format but provided it will look "sharp" enought for example in latex thesis)

Map I would like to save for example:

library(leaflet)
library(tidyverse)


data2 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_FRA_2_sp.rds"))

data3 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_ESP_2_sp.rds"))

data4 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_PRT_2_sp.rds"))

data5 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_GBR_2_sp.rds"))

data6 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_DEU_2_sp.rds"))

data7 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_NLD_2_sp.rds"))

data8 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_BEL_2_sp.rds"))

data9 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_POL_2_sp.rds"))

data10 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_CZE_2_sp.rds"))

data11 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_ITA_2_sp.rds"))

data12 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_CHE_2_sp.rds"))

data13 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_AUT_2_sp.rds"))

data14 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_HUN_2_sp.rds"))

data15 <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_UKR_2_sp.rds"))



random_long_lat <- 
  data.frame(
    long = sample(runif(1000, min = -7.5, max = 19.99), replace = F),
    lat = sample(runif(1000, min = 38.69, max = 60.75), replace = F)
  )

all <- rbind(data2, data3, data4, data5, 
             data6, data7, data8, data9, 
             data10, data11, data12, data13, 
             data14, data15)


all@data <- 
  all@data %>% 
  mutate(counts = rnorm(nrow(all), 100, sd = 35))

cuts <- c(0, 5, 20, 40, 80, 150, max(all@data$counts))
cuts <- colorBin("Greens", domain = all$counts, bins = cuts)

m <- 
  leaflet() %>% 
  addProviderTiles("CartoDB.Positron") %>% 
  addPolygons(data=all, stroke = TRUE, color = "white", weight="", smoothFactor = 0.95, 
              fillOpacity = 0.65, fillColor = ~cuts(all$counts)) %>% 
  addLegend(pal = cuts, 
            values = all$counts,
            labFormat = labelFormat(suffix = ""),
            opacity = 0.85, title = "How many point were counted in each region", position = "topright")


#library(htmlwidgets)
#saveWidget(m, file="C:/Users/petr7/Desktop/spatial_attacks.html")

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>