tm_shape {tmap} | R Documentation |
Specify the shape object
Description
Creates a tmap-element
that specifies a spatial data object, which we refer to as shape. Also the projection and covered area (bounding box) can be set. It is possible to use multiple shape objects within one plot (see tmap-element
).
Usage
tm_shape(
shp,
name = NULL,
is.master = NA,
projection = NULL,
bbox = NULL,
unit = NULL,
simplify = 1,
point.per = NA,
line.center = "midpoint",
filter = NULL,
raster.downsample = TRUE,
raster.warp = TRUE,
...
)
Arguments
shp |
shape object, which is an object from a class defined by the |
name |
name of the shape object (character) as it appears in the legend in |
is.master |
logical that determines whether this |
projection |
Map projection (CRS). Either a |
bbox |
bounding box. One of the following:
If unspecified, the current bounding box of |
unit |
desired units of the map. One of |
simplify |
simplification factor for spatial polygons and spatial lines. A number between 0 and 1 that indicates how many coordinates are kept. See the underlying function |
point.per |
specification of how points or text labels are plotted when the geometry is a multi line or a multi polygon. One of |
line.center |
specification of where points are placed for (multi)line geometries. Either |
filter |
logical vector which indicated per feature whether it should be included. Features for which filter is |
raster.downsample |
Should a raster shape (i.e. |
raster.warp |
Should a raster shape (i.e. |
... |
Arguments passed on to |
Value
References
Tennekes, M., 2018, tmap: Thematic Maps in R, Journal of Statistical Software, 84(6), 1-39, doi:10.18637/jss.v084.i06
See Also
Examples
current.mode <- tmap_mode("plot")
data(World, metro, rivers)
tm_shape(World) +
tm_polygons() +
tm_layout("Long lat coordinates (WGS84)", inner.margins=c(0,0,.1,0), title.size=.8)
World$highlighted <- ifelse(World$iso_a3 %in% c("GRL", "AUS"), "gold", "gray75")
tm_shape(World, projection=3857, ylim=c(.1, 1), relative = TRUE) +
tm_polygons("highlighted") +
tm_layout("Web Mercator projection. Although widely used, it is discouraged for
statistical purposes. In reality, Australia is 3 times larger than Greenland!",
inner.margins=c(0,0,.1,0), title.size=.6)
tm_shape(World, projection="+proj=robin") +
tm_polygons() +
tm_layout(
"Winkel-Tripel projection, adapted as default by the National Geographic Society for world maps.",
inner.margins=c(0,0,.1,0), title.size=.8)
tm_shape(World, projection="+proj=eck4") +
tm_polygons() +
tm_layout("Eckhart IV projection. Recommended in statistical maps for its equal-area property.",
inner.margins=c(0,0,.1,0), title.size=.8)
# different levels of simplification
## Not run:
tm1 <- tm_shape(World, projection="+proj=eck4", simplify = 0.05) + tm_polygons() +
tm_layout("Simplification: 0.05")
tm2 <- tm_shape(World, projection="+proj=eck4", simplify = 0.1) + tm_polygons() +
tm_layout("Simplification: 0.1")
tm3 <- tm_shape(World, projection="+proj=eck4", simplify = 0.25) + tm_polygons() +
tm_layout("Simplification: 0.25")
tm4 <- tm_shape(World, projection="+proj=eck4", simplify = 0.5) + tm_polygons() +
tm_layout("Simplification: 0.5")
require(tmaptools)
tmap_arrange(tm1, tm2, tm3, tm4)
## End(Not run)
# three groups of layers, each starting with tm_shape
## Not run:
tm_shape(World, projection="+proj=eck4") +
tm_fill("darkolivegreen3") +
tm_shape(metro) +
tm_bubbles("pop2010", col = "grey30", scale=.5) +
tm_shape(rivers) +
tm_lines("lightcyan1") +
tm_layout(bg.color="lightcyan1", inner.margins=c(0,0,.02,0), legend.show = FALSE)
## End(Not run)
# restore current mode
tmap_mode(current.mode)