Map component that adds an inset object, e.g. a mini map
Usage
tm_inset(
x = NULL,
height,
width,
margins,
between_margin,
stack,
position,
frame,
frame.lwd,
frame.r,
group.frame,
resize_as_group,
z
)
Arguments
- x
object to draw. Can be: bounding box, tmap object, ggplot2 object, grob object, image file name.
- height
height of the component in number of text line heights.
- width
width of the component in number of text line heights.
- margins
margins
- between_margin
Margin between
- stack
stack with other map components, either
"vertical"
or"horizontal"
.- position
An object created with
tm_pos_in()
ortm_pos_out()
. Or, as a shortcut, a vector of two values, specifying the x and y coordinates. The first is"left"
,"center"
or"right"
(or upper case, meaning tighter to the map frame), the second"top"
,"center"
or"bottom"
. Numeric values are also supported, where 0, 0 means left bottom and 1, 1 right top. See also vignette about positioning.- frame
frame
- frame.lwd
frame line width
- frame.r
Radius of the rounded frame corners. 0 means no rounding.
- group.frame
put frame around all components that are drawn on the same location. Whether a frame is drawn is still decided by the
frame
argument of the 'main' (first) component.- resize_as_group
in case a component if rescaled because of the limited space, rescale the other components proportionally?
- z
z index, e.g. the place of the component relative to the other componets
Examples
## map
bb = tmaptools::bb(NLD_prov[NLD_prov$name == "Utrecht",], ext = 1.05)
bb_Randstad =
sf::st_bbox(c(xmin = 120000, xmax = 150000, ymin = 460000, ymax = 500000), crs = 28992)
tm_shape(NLD_dist) +
tm_polygons(
fill = "dwelling_value",
fill.scale = tm_scale_continuous_pseudo_log(values = "-cols4all.pu_gn_div"),
col = NULL) +
tm_shape(NLD_muni) +
tm_borders(col = "black", lwd = 0.5) +
tm_shape(NLD_prov) +
tm_borders(col = "black", lwd = 1.5) +
tm_inset(bb_Randstad, height = 12, width = 12, position = c("left", "top")) +
tm_compass(position = c("left", "top"), )
#> <==================== v ===============>
#> integer(0)
#> <==================== b ===============>
#> integer(0)
#> <==================== by1 ===============>
#> NULL
#> <==================== by2 ===============>
#> NULL
#> <==================== by3 ===============>
#> NULL
#> </============================================>
#> <==================== v ===============>
#> integer(0)
#> <==================== b ===============>
#> integer(0)
#> <==================== by1 ===============>
#> NULL
#> <==================== by2 ===============>
#> NULL
#> <==================== by3 ===============>
#> NULL
#> </============================================>
#> <==================== v ===============>
#> integer(0)
#> <==================== b ===============>
#> integer(0)
#> <==================== by1 ===============>
#> NULL
#> <==================== by2 ===============>
#> NULL
#> <==================== by3 ===============>
#> NULL
#> </============================================>
## ggplot2
if (requireNamespace("ggplot2")) {
library(ggplot2)
p = ggplot(World, aes(x = gender, y = press, colour = continent)) +
geom_point() +
theme_bw()
tm_shape(World) +
tm_polygons(
fill = "gender",
fill.scale = tm_scale(values = "-cols4all.pu_gn_div")) +
tm_inset(p, height = 15, width = 20, position = tm_pos_in("left", "bottom"))
}
#> <==================== v ===============>
#> integer(0)
#> <==================== b ===============>
#> integer(0)
#> <==================== by1 ===============>
#> NULL
#> <==================== by2 ===============>
#> NULL
#> <==================== by3 ===============>
#> NULL
#> </============================================>
#> Warning: Removed 20 rows containing missing values or values outside the scale range
#> (`geom_point()`).