ComenzarEmpieza gratis

Saving a tmap plot

Saving tmap plots is easy with the tmap_save() function. The first argument, tm, is the plot to save, and the second, filename, is the file to save it to. If you leave tm unspecified, the last tmap plot printed will be saved.

The extension of the file name specifies the file type, for example .png or .pdf for static plots. One really neat thing about tmap is that you can save an interactive version which leverages the leaflet package. To get an interactive version, use tmap_save() but use the file name extension .html.

Este ejercicio forma parte del curso

Visualizing Geospatial Data in R

Ver curso

Instrucciones del ejercicio

Save your plot from the previous exercise in the following ways. Neither plot will display in your workspace, but you'll be able to take a look at them once you complete the exercise.

  • Save it as a static plot by specifying the filename population.png.
  • Save it as an interactive plot by specifying the filename population.html.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

library(sp)
library(tmap)

# Plot from last exercise
tm_shape(countries_spdf) +
  tm_grid(n.x = 11, n.y = 11, projection = "longlat") +
  tm_fill(col = "population", style = "quantile")  +
  tm_borders(col = "burlywood4")

# Save a static version "population.png"


# Save an interactive version "population.html"
Editar y ejecutar código