Learn R Programming

tmap (version 1.2)

tm_shape: Specify the shape object

Description

Creates a tmap-element that specifies the shape object. 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, is.master = NA, projection = NULL, bbox = NULL,
  unit = "km", unit.size = 1000, line.center.type = c("segment",
  "midpoint"), ...)

Arguments

shp
shape object, which is one of
  1. SpatialPolygons(DataFrame)

Value

item

  • is.master
  • projection
  • bbox
  • unit
  • unit.size
  • line.center.type
  • ...

code

bbox

describe

  • "feature", "single"If "feature" is specified, a pair of coordinates (used for bubbles, dots, and text labels) is chosen for each feature (i.e., a row in the SpatialLines(DataFrame)). If "segment" is specified, a pair of coordinates is chosed for each line segment.
  • "midpoint" or "centroid"The midpoint is the middle point on the line, so the coordinates (used for bubbles, dots, and text labels) correspond to the midpoints of the line segments. In case the first value is "feature", then per feature, the midpoint of the line segment that is closest to the centroid is taken.

See Also

read_shape to read ESRI shape files, set_projection, ../doc/tmap-nutshell.html{vignette("tmap-nutshell")}

Examples

Run this code
data(World, metro, rivers)

tm_shape(World, projection="longlat") + 
    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="merc", ylim=c(.1, 1), relative = TRUE) + 
    tm_polygons("highlighted") + 
tm_layout("Mercator projection. Although used in Google Maps, 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="wintri") + 
    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) +
    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)

# three groups of layers, each starting with tm_shape
tm_shape(World) +
    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)

Run the code above in your browser using DataLab