1

I want to create a map using the library tmap (to save loads of bother with shapefiles).

Then I convert into leaflet, with a drop down menu to select which data I want to show.

In the example below, I wish for a select option to show either HPI and pop_est instead of World. I have managed to do this but I have not worked out how to have it show it only shows one by default (i.e HPI)

#Load libraries
library(tmap)
library(leaflet)
#Load Data
data("World")

#Create Tmap object 
    HPI<-tm_shape(World2,name="HPI") +
      tm_polygons("HPI",alpha=0.5)

    Pop<-tm_shape(World2,name="Pop") +
      tm_polygons("pop_est",alpha=0.5)

    #Convert to leaflet
    lf<-tmap_leaflet(c(HPI,Pop)) 

#Print leaflet map
lf

enter image description here

SLE
  • 65
  • 1
  • 17

0 Answers0