interactive map using tmap package with RMarkdown

1.5k views Asked by At

I am trying to write a report about my program and to show my work using RMarkdown. However, the map that I am currently using is generated by tmap package.

The shapefile can be downloaded here

The way that I make it interactive using R is

library(tmap)
library(rgdal)
map <- readOGR("Malaysia SHP", "MYS_adm1")
tmap_mode("view")
tm_shape(map) + tm_polygons()

This would generate an interactive map that we can directly access from R.

I want to include this in my RMarkdown and still make it interactive. I know there is a package called leaflet that is usually used to create an interactive map. Is there any way to create an interactive map using tmap in RMarkdown without using leaflet?

Any helps would be appreciated. Thank you!

1

There are 1 answers

0
Martijn Tennekes On BEST ANSWER

Thanks for this bug report! It is now fixed in the development version. See https://github.com/mtennekes/tmap how to install this.

If you cannot install the development version, a workaround is:

tmap_leaflet(tm_shape(map) + tm_polygons())

It coerces a tmap object to a leaflet object.