Learn R Programming

tmap (version 1.6-1)

save_tmap: Save tmap

Description

Save tmap to a file, such as png, jpg, or pdf.

Usage

save_tmap(tm = NULL, filename = NULL, width = NA, height = NA, units = NA, dpi = 300, outer.margins = 0, asp = NULL, scale = NA, insets_tm = NULL, insets_vp = NULL, verbose = TRUE, ...)

Arguments

tm
tmap object
filename
filename including extension, and optionally the path. The extensions pdf, eps, svg, wmf (Windows only), png, jpg, bmp, or tiff are supported. If the extension is missing, the file will be saved as png image
width
width. Units are set with the argument units. If set to NA and height is specified, it will be height * aspect ratio. If both width and height are not specified, then the width of the current plotting window will be taken.
height
height. Units are set with the argument units. If set to NA and width is specified, it will be width / aspect ratio. If both width and height are not specified, then the height of the current plotting window will be taken.
units
units for width and height ("in", "cm", or "mm"). By default, pixels ("px") are used if either width or height is set to a value greater than 50. Else, the units are inches ("in")
dpi
dots per inch. Only applicable for raster graphics.
outer.margins
overrides the outer.margins argument of tm_layout (unless set to NA)
asp
if specified, it overrides the asp argument of tm_layout. Tip: set to 0 if map frame should be placed on the edges of the image.
scale
overrides the scale argument of tm_layout (unless set to NA)
insets_tm
tmap object of an inset map, or a list of tmap objects of multiple inset maps. The number of tmap objects should be equal to the number of viewports specified with insets_vp.
insets_vp
viewport of an inset map, or a list of viewports of multiple inset maps. The number of viewports should be equal to the number of tmap objects specified with insets_tm.
verbose
should information messages be returned?
...
arguments passed on to device functions or to saveWidget

Examples

Run this code
## Not run: 
# 	data(NLD_muni, NLD_prov)
# 	m <- tm_shape(NLD_muni) +
# 		     tm_fill(col="population", convert2density=TRUE, 
#                  style="kmeans", 
#                  title=expression("Population (per " * km^2 * ")"), 
#                  legend.hist=FALSE) +
# 		     tm_borders("black", alpha=.5) + 
# 		 tm_shape(NLD_prov) +
# 		     tm_borders("grey25", lwd=2) +
# 	     tm_format_NLD(inner.margins = c(.02, .15, .06, .15)) + 
# 	     tm_scale_bar(position = c("left", "bottom")) +
# 	     tm_compass(position=c("right", "bottom")) + 
# 	     tm_style_classic()
# 	
# 	save_tmap(m, "choropleth.png", height=7)
# 	
# 	data(World)
# 	m2 <- tm_shape(World) +
# 		tm_fill("well_being", id="name", title="Well-being") +
# 		tm_format_World()
# 
# 	# save image
# 	save_tmap(m2, "World_map.png", width=1920, height=1080, asp=0)
# 
# 	# cut left inner margin to make sure Antarctica is snapped to frame
# 	save_tmap(m2 + tm_layout(inner.margins = c(0, -.1, 0.05, 0.01)), 
#         "World_map2.png", width=1920, height=1080, asp=0)
# 	
# 	# save interactive plot
# 	save_tmap(m2, "World_map.html")
# ## End(Not run)

Run the code above in your browser using DataLab