R/tmap_grob.R

Defines functions tmap_grob

Documented in tmap_grob

#' Export to grob object
#' 
#' Export a tmap plot object to a grob object (from the grid package).
#' 
#' @param tm tmap object
#' @export
#' @return A grob object when one page is generated, or a list of grob objects when multiple pages are generated.
#' @example ./examples/tmap_grob.R
tmap_grob = function(tm) {
	.tmapOptions <- get("tmapOptions", envir = .TMAP_CACHE)
	show.messages <-.tmapOptions$show.messages
	
	
	x = print(tm, show = FALSE)
	asp = x$gps$plot1$tm_layout$shape.dasp
	if (length(x$grb) == 1L) {
		grb = x$grb[[1]]
		if (show.messages) message("Note that the aspect ratio for which the grob has been generated is ", format(asp, digits = 3))
	} else {
		grb = x$grb
		if (show.messages) message("A list of grobs will be returned, one for each page. Note that the aspect ratio for which each grob has been generated is ", format(asp, digits = 3))
	}
	grb
}

Try the tmap package in your browser

Any scripts or data that you put into this service are public.

tmap documentation built on Sept. 13, 2023, 1:07 a.m.