1

We have some drawings of world maps with data, made using R's leaflet package. Is it possible to export the result into svg format, in order to get the objects separable to tune the layout further, let's say, in inkscape?

Here is the minimal example of data from another question

    # necessary libraries
        library("leaflet")
        library("htmltools")
        library("leaflet.minicharts")

    # generated some data
        basins <- read.table(text="basin,lat,lon,res.density,rel.area
        Central Sumatra,1,96,16.7,75
        North Sea,58.4,2,20,24
        Maracaibo basin,9,-71,74.4,14.3
        Los Angeles,33,-118,31.2,32", header=T, sep=",")

    # plotting itself
        m2<-   leaflet(data = basins) %>% 
              addTiles() %>% 
            addCircleMarkers(~lon, ~lat ,radius=0,label=~htmlEscape(basin),labelOptions=labelOptions(noHide=T,textOnly=TRUE,direction="bottom", offset=c(0,5))) %>%
              addMinicharts(basins$lon, basins$lat, type="bar", chartdata = basins[, c("res.density", "rel.area")], width = 50, height = 60,legend=FALSE,showLabels=TRUE) %>%
addLegend(position='bottomleft',colors=c("#1f77b4","#ff7f0e"),opacity=0.8,labels=c("some strange value in thousands/km2","another value measured in km2" ))  
        m2

Trying to export it as usual for plots:

 svg("file.svg")
    m2
    dev.off()

does not work. I understand that this is some another type of object than generated by plot() commands. Is it ever treatable as vectors?

astrsk
  • 375
  • 6
  • 20
  • I have not seen any way to export as svg. You can save as PNG using saveWidget. If you want a static map, why not use the tmap package? – TimSalabim Aug 13 '17 at 14:50
  • tmap has some nasty issues with dependencies. geos, rgdal, sf(??)..., something else. Strangely, most of them were to be resolved by manual installation from sources, and not normally from R repos; and half of them are still not recognized by R. As a result, I did not manage yet to install neither tmap, nor cartography, and some other cartographic packages depending on those (rosm, rgdal etc). In a rush we had to appeal to the first ever working solution for mapping. – astrsk Aug 13 '17 at 15:22
  • Pretty much all geographic software has external dependencies such as gdal because not all data is longlat points. But getting these installed is usually straight forward. Which os are you on? – TimSalabim Aug 13 '17 at 15:34
  • It is Ubuntu 16.04 (LTS), both 32 and 64 version on two different computers. Internet is full of claims that geos, gdal etc have problems with installation. I had to install geos manually (geos-3.5.0), then R recognized it, so geos dependencies disappeared in some packages. But succesful installing manually rgdal (gdal-2.2.1) did not alter R behaviour: ERROR: dependency ‘rgdal’ is not available for package ‘rosm’ ERROR: dependencies ‘tmaptools’, ‘rgdal’, ‘mapview’ are not available for package ‘tmap’ and so on – astrsk Aug 13 '17 at 16:07
  • Have you tried installing those packages that it complains about? Obviously tmap can only be installed when the dependencies/imports are installed. I have no problems using any of these on Ubuntu 16.04 using ubuntu-gis repository. – TimSalabim Aug 13 '17 at 16:19
  • I tried many times. The first package to complain (inside R) is rgdal which is absent in repos. I appeared to have a rather old R version (3.2.3, 'Wooden Christmas-Tree") from Ubuntu native repositories, and rgdal is pretending to work with R > 3.3.0. So maybe it is right time to stop relying on ubuntu repos and to upgrade the whole stuff. – astrsk Aug 13 '17 at 20:43
  • I currently use https://cran.wu.ac.at/bin/linux/ubuntu for R and http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu for GIS stuff. – TimSalabim Aug 14 '17 at 05:48

0 Answers0