96
Package ‘tmap’ May 7, 2016 License GPL-3 Title Thematic Maps Type Package LazyLoad yes Description Thematic maps are geographical maps in which spatial data distributions are visual- ized. This package offers a flexible, layer-based, and easy to use approach to create the- matic maps, such as choropleths and bubble maps. Version 1.4-1 Date 2016-05-06 Depends R (>= 3.0), Imports methods, sp, raster (>= 2.5-2), grid, rgdal, rgeos, classInt, htmltools, htmlwidgets, KernSmooth, osmar, RColorBrewer, spdep, XML, leaflet, geosphere Suggests rmarkdown, knitr, OpenStreetMap VignetteBuilder knitr RoxygenNote 5.0.1 NeedsCompilation no Author Martijn Tennekes [aut, cre], Joel Gombin [ctb], Sebastian Jeworutzki [ctb], Kent Russell [ctb], Richard Zijdeman [ctb] Maintainer Martijn Tennekes <[email protected]> Repository CRAN Date/Publication 2016-05-07 00:36:45 R topics documented: tmap-package ........................................ 3 +.tmap ............................................ 6 1

Package ‘tmap’ · 2016. 8. 5. · Package ‘tmap’ May 7, 2016 License GPL-3 Title Thematic Maps Type Package LazyLoad yes Description Thematic maps are geographical maps in

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

  • Package ‘tmap’May 7, 2016

    License GPL-3Title Thematic MapsType PackageLazyLoad yesDescription Thematic maps are geographical maps in which spatial data distributions are visual-

    ized. This package offers a flexible, layer-based, and easy to use approach to create the-matic maps, such as choropleths and bubble maps.

    Version 1.4-1Date 2016-05-06Depends R (>= 3.0),Imports methods, sp, raster (>= 2.5-2), grid, rgdal, rgeos, classInt,

    htmltools, htmlwidgets, KernSmooth, osmar, RColorBrewer, spdep,XML, leaflet, geosphere

    Suggests rmarkdown, knitr, OpenStreetMapVignetteBuilder knitrRoxygenNote 5.0.1NeedsCompilation noAuthor Martijn Tennekes [aut, cre],

    Joel Gombin [ctb],Sebastian Jeworutzki [ctb],Kent Russell [ctb],Richard Zijdeman [ctb]

    Maintainer Martijn Tennekes Repository CRANDate/Publication 2016-05-07 00:36:45

    R topics documented:tmap-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3+.tmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    1

  • 2 R topics documented:

    animation_tmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7append_data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8approx_areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9bb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10calc_densities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12crop_shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14geocode_OSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14get_asp_ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15get_IDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16get_proj4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16land . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18map_coloring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18metro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20offset_line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20points_to_raster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21poly_to_raster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23print.tmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24qtm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25read_GPX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27read_osm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28read_shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30rivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32sample_dots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32save_tmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34sbind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35set_projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36smooth_map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37smooth_raster_cover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41split.SpatialPolygons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41style_catalogue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42tmap-element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43tmap_leaflet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44tmap_mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45tmap_style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47tm_bubbles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48tm_compass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52tm_credits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53tm_facets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55tm_fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59tm_grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63tm_iso . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64tm_layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65tm_lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73tm_raster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77tm_scale_bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81tm_shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82tm_text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84tm_view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

  • tmap-package 3

    tm_xlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92write_shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

    Index 94

    tmap-package Thematic Maps

    Description

    Thematic maps are geographical maps in which spatial data distributions are visualized. This pack-age offers a flexible, layer-based, and easy to use approach to create thematic maps, such as choro-pleths and bubble maps. It is based on the grammar of graphics, and resembles the syntax ofggplot2.

    Details

    This page provides a brief overview of all package functions. See vignette("tmap-nutshell")for a short introduction with examples. See vignette("tmap-modes") for a short demo of the twooutput modes: plot and interactive view.

    Quick plotting method

    qtm To plot a thematic map————————— —————————————————————————————————

    Main plotting method

    Shape specification:

    tm_shape To specify a shape object————————— —————————————————————————————————

    Aesthetics layers:

    tm_fill To create a polygon layer (without borders)tm_borders To create polygon borderstm_polygons To create a polygon layer with borderstm_bubbles To create a layer of bubblestm_dots To create a layer of dotstm_lines To create a layer of linestm_raster To create a raster layer

    ../doc/tmap-nutshell.html../doc/tmap-modes.html

  • 4 tmap-package

    tm_text To create a layer of text labels————————— —————————————————————————————————

    Facetting (small multiples)

    tm_facets To define facets————————— —————————————————————————————————

    Attributes:

    tm_grid To create grid linestm_scale_bar To create a scale bartm_compass To create a map compasstm_credits To create a text for creditstm_xlab and tm_ylab To create axis labels————————— —————————————————————————————————

    Layout element:

    tm_layout To adjust the layout (main function)tm_legend Shortcut to adjust the legendtm_view Options for the interactive view mode————————— —————————————————————————————————

    Change options:

    tmap_mode To set the tmap mode: "plot" or "view"ttm To toggle between the modestmap_style To set the default style————————— —————————————————————————————————

    Handy tool functions

    bb To create, extract or modify a bounding boxgeocode_OSM To get geocode based on locationget_asp_ratio To get the aspect ratio of a shape objectget_IDs To get ID values of a shape objectappend_data To append a data frame to a shape objectapprox_areas To approximate area sizes of polygonscalc_densities To calculate density valuesget_projection To get the map projectionset_projection To set the map projection

  • tmap-package 5

    split To split a shape objectsbind To bind shape objectscrop_shape To crop shape objectsmap_coloring To color polygons with different colors for adjacent polygons————————— —————————————————————————————————

    Generate spatial objects

    smooth_map To create a smooth map (raster, contour lines and dasymetric polygons)smooth_raster_cover To create a smooth cover of a raster objectsample_dots To sample dots from polygonspoints_to_raster To bin spatial points to a rasterpoly_to_raster To convert polygons to a raster————————— —————————————————————————————————

    Input functions

    read_shape To read a shape objectread_GPX To read a GPX fileread_osm To read Open Street Map data————————— —————————————————————————————————

    Output functions

    print Plot in graphics device or view interactively in web browser or RStudio’s viewer panetmap_leaflet Obtain a leaflet widget objectanimation_tmap Create an animationsave_tmap To save thematic maps (both in plot and view mode)write_shape To write a shape object————————— —————————————————————————————————

    Spatial datasets

    World World country data (spatial polygons)

  • 6 +.tmap

    Europe European country data (spatial polygons)NLD_prov Netherlands province data (spatial polygons)NLD_muni Netherlands municipal data (spatial polygons)metro Metropolitan araes (spatial points)rivers Rivers (spatial lines)land Global land cover (spatial grid)————————— —————————————————————————————————

    Author(s)

    Martijn Tennekes

    See Also

    vignette("tmap-nutshell")

    vignette("tmap-modes")

    +.tmap Stacking of tmap elements

    Description

    The plus operator allows you to stack tmap-elements, and groups of tmap-elements.

    Usage

    ## S3 method for class 'tmap'e1 + e2

    Arguments

    e1 first tmap-element

    e2 second tmap-element

    See Also

    tmap-element and vignette("tmap-nutshell")

    ../doc/tmap-nutshell.html../doc/tmap-modes.html../doc/tmap-nutshell.html

  • animation_tmap 7

    animation_tmap Create animation

    Description

    Create a gif or mpeg animation from a tmap plot. The free tool ImageMagick is required.

    Usage

    animation_tmap(tm, filename = "animation.gif", width = NA, height = NA,delay = 40)

    Arguments

    tm tmap object. In order to create a series of tmap plots, which will be the frames ofthe animation, it is important to set nrow and ncol in tm_facets, for otherwisea small multiples plot is generated. Commonly, where one map is shown at atime, both nrow and ncol are set to 1.

    filename filename of the video (should be a .gif or .mpg file)

    width width of the animation file (in pixels)

    height height of the animation file (in pixels)

    delay delay time between images (in 1/100th of a second)

    Note

    Not only tmap plots are supported, but any series of R plots.

    Examples

    ## Not run:data(World, metro, Europe)

    m1

  • 8 append_data

    ## End(Not run)

    append_data Append data to a shape object

    Description

    Data, in the format of a data.frame, is appended to a shape object. This is either done by a right joinwhere keys are specified for both data and shape, or by fixed order.

    Usage

    append_data(shp, data, key.shp = NULL, key.data = NULL,ignore.duplicates = FALSE, ignore.na = FALSE,fixed.order = is.null(key.data) && is.null(key.shp))

    Arguments

    shp shape object, which is one of

    1. SpatialPolygons(DataFrame)

    2. SpatialPoints(DataFrame)

    3. SpatialLines(DataFrame)

    4. SpatialGrid(DataFrame)

    5. SpatialPixels(DataFrame)

    data data.frame

    key.shp variable name of shp map data to be matched with key.data. If not specified,and fixed.order is FALSE, the ID’s of the polygons/lines/points are taken.

    key.data variable name of data to be matched with key.shp. If not specified, and fixed.orderis FALSE, the row names of data are taken.

    ignore.duplicates

    should duplicated keys in data be ignored? (FALSE by default)

    ignore.na should NA values in key.data and key.shp be ignored? (FALSE by default)

    fixed.order should the data be append in the same order as the shapes in shp?

    Value

    Shape object with appended data.

  • approx_areas 9

    Examples

    ## Not run:data(Europe)

    f

  • 10 bb

    unit.size size of the unit in terms of coordinate units. The coordinate system of many pro-jections is approximately in meters while thematic maps typically range manykilometers, so by default unit="km" and unit.size=1000 (meaning 1 kilome-ter equals 1000 coordinate units).

    total.area total area size of shp in number of squared units (by default kilometers). Usefulif the total area of the shp differs from a reference total area value.

    Details

    To approximate the sizes in squared units, either the total.area or the unit.size is required.Note that this method is an approximation, since it depends on the used projection and the level ofdetail of the SpatialPolygons object. Projections with equal-area property are highly recommended.

    Value

    Numeric vector of area sizes.

    Examples

    data(NLD_muni)

    NLD_muni$area

  • bb 11

    If x is not specified, a bounding box can be created from scratch (see details.

    ext Extension factor of the bounding box. If 1, the bounding box is unchanged. Val-ues smaller than 1 reduces the bounding box, and values larger than 1 enlargesthe bounding box. This argument is a shortcut for both width and height withrelative=TRUE. If a negative value is specified, then the shortest side of thebounding box (so width or height) is extended with ext, and the longest side isextended with the same absolute value. This is especially useful for boundingboxes with very low or high aspect ratios.

    cx center x coordinate

    cy center y coordinate

    width width of the bounding box. These are either absolute or relative (depending onthe argument relative).

    height height of the bounding box. These are either absolute or relative (depending onthe argument relative).

    xlim limits of the x-axis. These are either absolute or relative (depending on theargument relative).

    ylim limits of the y-axis. See xlim.

    relative boolean that determines whether relative values are used for width, height,xlim and ylim or absolute. If x is unspecified, relative is set to "FALSE".

    current.projection

    projection string (see set_projection) of the that corresponds to the

    projection projection string (see set_projection) to transform the bounding box to.

    as.extent should the bounding box be returned as extent? If FALSE (default) then a matrixis returned

    Details

    An existing bounding box (defined by x) can be modified as follows:

    • Using the extension factor ext.

    • Changing the width and height with width and height. The argument relavitve determineswhether relative or absolute values are used.

    • Setting the x and y limits. The argument relavitve determines whether relative or absolutevalues are used.

    A new bounding box can be created from scratch as follows:

    • Using the extension factor ext.

    • Setting the center coorinates cx and cy, together with the width and height.

    • Setting the x and y limits xlim and ylim

    Value

    bounding box (see argument as.extent)

  • 12 calc_densities

    See Also

    geocode_OSM

    Examples

    ## load shapesdata(NLD_muni)data(World)

    ## get bounding box (similar to sp's function bbox)bb(NLD_muni)

    ## extent it by factor 1.10bb(NLD_muni, ext=1.10)

    ## convert to longlatbb(NLD_muni, projection="longlat")

    ## change existing bounding boxbb(NLD_muni, ext=1.5)bb(NLD_muni, width=2, relative = TRUE)bb(NLD_muni, xlim=c(.25, .75), ylim=c(.25, .75), relative = TRUE)bb("Limburg", projection = "rd")

    bb_italy

  • calc_densities 13

    Description

    Transpose quantitative variables to densitiy variables, which are often needed for choroplets. Forexample, the colors of a population density map should correspond population density counts ratherthan absolute population numbers.

    Usage

    calc_densities(shp, var, unit = "km", unit.size = 1000, total.area = NA,suffix = "", drop = TRUE)

    Arguments

    shp a shape object, i.e., a SpatialPolygons(DataFrame)

    var name(s) of a qualtity variable name contained in the shp data

    unit the preferred unit, for instance, "km", "m", or "miles". Density values are cal-culated in var/unit^2.

    unit.size size of the unit in terms of coordinate units. The coordinate system of many pro-jections is approximately in meters while thematic maps typically range manykilometers, so by default unit="km" and unit.size=1000 (meaning 1 kilome-ter equals 1000 coordinate units).

    total.area total area size of shp in number of squared units (by default kilometers). Usefulif the total area of the shp differs from a reference total area value.

    suffix character that is appended to the variable names. The resulting names are usedas column names of the returned data.frame.

    drop boolean that determines whether an one-column data-frame should be returnedas a vector

    Value

    Vector or data.frame (depending on whether length(var)==1 with density values. This can beappended directly to the shape file with append_data with fixed.order=TRUE.

    Examples

    data(NLD_muni)

    NLD_muni_pop_per_km2

  • 14 geocode_OSM

    crop_shape Crop shape object

    Description

    Crop a shape object (from class Spatial-class or Raster).

    Usage

    crop_shape(x, y, ...)

    Arguments

    x shape object, i.e. an object from class Spatial-class or Raster

    y bounding box (2 by 2 matrix), an extent, or a shape object from which thebounding box is extracted.

    ... arguments passed on to crop

    Details

    This function is a wrapper around crop from the raster package. It does two things in addition:SpatialGrid objects are allowed, and if y is a shape object with a different projection, it is tem-porarily reprojected in order to obtain a bounding box by which x is cropped.

    See Also

    bb

    Examples

    data(Europe, land)

    land_europe

  • get_asp_ratio 15

    Usage

    geocode_OSM(q, projection = "longlat")

    Arguments

    q a character that specifies a search query. For instance "India" or "CBS Weg 11, Heerlen, Netherlands".

    projection projection in which the coordinates and bounding box are returned. Either aPROJ.4 character string or a shortcut. See get_proj4 for a list of shortcut val-ues.

    Value

    A list of two items: "coords", a vector containing the longitude and latitude coordinates, and"bbox", the corresponding bounding box.

    See Also

    bb

    Examples

    geocode_OSM("India")

    geocode_OSM("CBS Weg 1, Heerlen")

    geocode_OSM("CBS Weg 1, Heerlen", projection = "rd")

    get_asp_ratio Get aspect ratio

    Description

    Get the aspect ratio of a shape object, i.e., the map width devided by the map height.

    Usage

    get_asp_ratio(x, width = 700, height = 700, res = 100)

    Arguments

    x shape object (either Spatial or a Raster) or a tmap object.

    width See details; only applicable if x is a tmap object.

    height See details; only applicable if x is a tmap object.

    res See details; only applicable if x is a tmap object.

  • 16 get_proj4

    Details

    The arguments width, height, and res are passed on to png. If x is a tmap object, a temporarilypng image is created to calculate the aspect ratio of a tmap object. The default size of this image is700 by 700 pixels at 100 dpi.

    Value

    aspect ratio

    get_IDs Get ID’s of the shape items

    Description

    Get ID’s of the shape items. For polygons and lines, the ID attribute is used. For points, thecoordinates are used.

    Usage

    get_IDs(shp)

    Arguments

    shp shape object, which is one of

    1. SpatialPolygons(DataFrame)2. SpatialPoints(DataFrame)3. SpatialLines(DataFrame)

    Value

    vector of ID’s

    get_proj4 Get a PROJ.4 character string

    Description

    Get full PROJ.4 string from either an existing PROJ.4 string or a shortcut.

    Usage

    get_proj4(x)

  • get_proj4 17

    Arguments

    x a PROJ.4 character string or a shortcut, which is one of:

    "longlat" Not really a projection, but a plot of the longitude-latitude coordi-nates (WGS84 datum).

    "wintri" Winkel Tripel (1921). Popular projection that is useful in worldmaps. It is the standard of world maps made by the National GeographicSociety. Type: compromise

    "robin" Robinson (1963). Another popular projection for world maps. Type:compromise

    "eck4" Eckert IV (1906). Projection useful for world maps. Area sizes arepreserved, which makes it particularly useful for truthful choropleths. Type:equal-area

    "hd" Hobo-Dyer (2002). Another projection useful for world maps in whicharea sizes are preserved. Type: equal-area

    "gall" Gall (Peters) (1855). Another projection useful for world maps inwhich area sizes are preserved. Type: equal-area

    "merc" Web Mercator. Projection in which shapes are locally preserved, a vari-ant of the original Mercator (1569), used by Google Maps, Bing Maps, andOpenStreetMap. Areas close to the poles are inflated. Type: conformal

    "utmXX(s)" Universal Transverse Mercator. Set of 60 projections where eachprojection is a traverse mercator optimized for a 6 degree longitude range.These ranges are called UTM zones. Zone 01 covers -180 to -174 degrees(West) and zone 60 174 to 180 east. Replace XX in the character stringwith the zone number. For southern hemisphere, add "s". So, for instance,the Netherlands is "utm31" and New Zealand is "utm59s"

    "mill" Miller (1942). Projetion based on Mercator, in which poles are dis-played. Type: compromise

    "eqc0" Equirectangular (120). Projection in which distances along meridiansare conserved. The equator is the standard parallel. Also known as PlateCarr\’ee. Type: equidistant

    "eqc30" Equirectangular (120). Projection in which distances along meridiansare conserved. The latitude of 30 is the standard parallel. Type: equidistant

    "eqc45" Equirectangular (120). Projection in which distances along meridiansare conserved. The latitude of 45 is the standard parallel. Also known asGall isographic. Type: equidistant

    "rd" Rijksdriehoekstelsel. Triangulation coordinate system used in the Nether-lands.

    EPSG code A valid code from the EPSG database

    Value

    validated PROJ.4 character string

    See Also

    http://en.wikipedia.org/wiki/List_of_map_projections for a overview of projections. http:

    http://en.wikipedia.org/wiki/List_of_map_projectionshttp://trac.osgeo.org/proj/

  • 18 map_coloring

    //trac.osgeo.org/proj/ for the PROJ.4 project home page. An extensive list of PROJ.4 codescan be created with rgdal’s make_EPSG.

    land Spatial data of global land cover

    Description

    Spatial data of global land cover, of class SpatialGridDataFrame. The data includes a populationtimes series from 1950 to (forecasted) 2030. All metro areas with over 1 million inhabitants in 2010are included.

    Usage

    data(land)

    Details

    Important: publication of these maps is only allowed when cited to Tateishi et al. (2014), and when"Geospatial Information Authority of Japan, Chiba University and collaborating organizations." isshown. See http://www.iscgm.org/gm/glcnmo.html#use.

    Source

    http://www.iscgm.org/gm/glcnmo.html

    References

    Production of Global Land Cover Data - GLCNMO2008, Tateishi, R., Thanh Hoan, N., Kobayashi,T., Alsaaideh, B., Tana, G., Xuan Phong, D. (2014), Journal of Geography and Geology, 6 (3).

    map_coloring Map coloring

    Description

    Color the polygons of a map such that adjacent polygons have different colors

    Usage

    map_coloring(x, algorithm = "greedy", ncols = NA, minimize = FALSE,palette = NULL, contrast = 1)

    http://trac.osgeo.org/proj/http://trac.osgeo.org/proj/http://www.iscgm.org/gm/glcnmo.html#usehttp://www.iscgm.org/gm/glcnmo.html

  • map_coloring 19

    Arguments

    x Either a SpatialPolygons(DataFrame) or an adjacency list.

    algorithm currently, only "greedy" is implemented.

    ncols number of colors. By default it is 8 when palette is undefined. Else, it is set tothe length of palette

    minimize logical that determines whether algorithm will search for a minimal number ofcolors. If FALSE, the ncols colors will be picked by a random procedure.

    palette color palette.

    contrast vector of two numbers that determine the range that is used for sequential anddiverging palettes (applicable when auto.palette.mapping=TRUE). Both num-bers should be between 0 and 1. The first number determines where the palettebegins, and the second number where it ends. For sequential palettes, 0 meansthe brightest color, and 1 the darkest color. For diverging palettes, 0 means themiddle color, and 1 both extremes. If only one number is provided, this numberis interpreted as the endpoint (with 0 taken as the start).

    Value

    If palette is defined, a vector of colors is returned, otherwise a vector of color indices.

    Examples

    ## Not run:qtm(World, fill="MAP_COLORS", fill.palette="Pastel2")tm_shape(World) +

    tm_polygons("MAP_COLORS", palette="Pastel2")

    ## End(Not run)data(World, metro)

    World$color

  • 20 offset_line

    metro Spatial data of metropolitan areas

    Description

    Spatial data of metropolitan areas, of class SpatialPointsDataFrame. The data includes a popu-lation times series from 1950 to (forecasted) 2030. All metro areas with over 1 million inhabitantsin 2010 are included.

    Usage

    data(metro)

    Source

    http://esa.un.org/unpd/wup/CD-ROM/

    References

    United Nations, Department of Economic and Social Affairs, Population Division (2014). WorldUrbanization Prospects: The 2014 Revision, CD-ROM Edition.

    offset_line Create a double line or offset line

    Description

    Create a double line or offset line. The double line can be useful for visualizing two-way tracks oremulating objects such as railway tracks. The offset line can be useful to prevent overlapping ofspatial lines.

    Usage

    offset_line(shp, offset)

    double_line(shp, width, sides = "both")

    Arguments

    shp SpatialLines(DataFrame)

    offset offset from the original lines

    width width between the left and righthand side

    sides character value that specifies which sides are selected: "both", "left", or"right". The default is "both". For the other two options, see also the shortcutfunction offset_line.

    http://esa.un.org/unpd/wup/CD-ROM/

  • points_to_raster 21

    Examples

    ### Demo to visualise the route of the Amstel Gold Race, a professional cycling race## Not run:tmpdir

  • 22 points_to_raster

    Arguments

    shp shape object. Either a SpatialPoints(DataFrame) or a SpatialGrid(DataFrame).

    nrow number of raster rows. If NA, it is automatically determined by N and the aspectratio of shp.

    ncol number of raster columns. If NA, it is automatically determined by N and theaspect ratio of shp.

    N preferred number of raster cells.

    by name of a data variable which should be a factor. The points are split andcounted according to the levels of this factor.

    to.Raster logical; should the output be a Raster object (TRUE), or a SpatialGridDataFrame(FALSE). If TRUE, a RasterBrick is returned when by is specified, and a RasterLayerwhen by is unspecified.

    Details

    This function is a wrapper around rasterize.

    Value

    A SpatialGridDataFrame, or a Raster object when (to.Raster=TRUE)

    See Also

    poly_to_raster

    Examples

    ## Not run:data(NLD_muni, NLD_prov)

    # sample points (each point represents 1000 people)NLD_muni_points

  • poly_to_raster 23

    poly_to_raster Convert spatial polygons to a raster

    Description

    Convert spatial polygons to a raster. The value of each raster cell will be the polygon ID number.Alternatively, if copy.data, the polygon data is appended to each raster cell.

    Usage

    poly_to_raster(shp, nrow = NA, ncol = NA, N = 250000, use.cover = FALSE,copy.data = FALSE, to.Raster = !copy.data, ...)

    Arguments

    shp shape object. Either a SpatialPoints(DataFrame) or a SpatialGrid(DataFrame).

    nrow number of raster rows. If NA, it is automatically determined by N and the aspectratio of shp.

    ncol number of raster columns. If NA, it is automatically determined by N and theaspect ratio of shp.

    N preferred number of raster cells.

    use.cover logical; should the cover method be used? This method determines per rastercell which polygon has the highest cover fraction. This method is better, butvery slow, since N times the number of polygons combinations are processed(using the getCover argument of rasterize). By default, when a raster cellis covered by multiple polygons, the last polygon is taken (see fun argment ofrasterize))

    copy.data should the polygon data be appended to the raster? Only recommended when Nis small.

    to.Raster logical; should the output be a Raster object (TRUE), or a SpatialGridDataFrame(FALSE). If TRUE, a RasterBrick is returned when by is specified, and a RasterLayerwhen by is unspecified. For very large rasters, use TRUE, since large Raster ob-jects are accessed from disk.

    ... arguments passed on to rasterize

    Value

    A SpatialGridDataFrame, or a Raster object when (to.Raster=TRUE)

    See Also

    points_to_raster

  • 24 print.tmap

    Examples

    ## Not run:data(NLD_muni)

    # choropleth of 65+ population percentagesqtm(NLD_muni, fill="pop_65plus", format="NLD")

    # rasterized versionNLD_rst

  • qtm 25

    Value

    If mode=="plot", then a list is returned with the processed shapes and the metadata. If mode=="view",a leaflet object is returned (see also tmap_leaflet)

    qtm Quick thematic map plot

    Description

    Draw a thematic map quickly.

    Usage

    qtm(shp, fill = NA, bubble.size = NULL, bubble.col = NULL,dot.col = NULL, text = NULL, text.size = 1, text.col = NA,line.lwd = NULL, line.col = NULL, raster = NA, borders = NA,scale = NA, title = NA, projection = NULL, format = NULL,style = NULL, basemaps = NA, ...)

    Arguments

    shp shape object, which is one of

    1. SpatialPolygons(DataFrame)2. SpatialPoints(DataFrame)3. SpatialLines(DataFrame)4. SpatialGrid(DataFrame)5. SpatialPixels(DataFrame)6. RasterLayer, RasterStack, or RasterBrick

    In "view" mode (see tmap_mode) there are two other options. 1) If omitted, aninteractive map without thematic layers is opened. 2) In addition, if a character isprovided, this character is used as a search query for OpenStreetMap nominatim.This will position the interactive map accordingly. Arguments of tm_view, suchas set.view can be passed on directly.

    fill either a color to fill the polygons, or name of the data variable in shp to draw achoropleth. Only applicable when shp is type 1 (see above).

    bubble.size name of the data variable in shp for the bubble map that specifies the sizes of thebubbles. If neither bubble.size nor bubble.col is specified, no bubble map isdrawn. Only applicable when shp is type 1, 2, or 3 (see above).

    bubble.col name of the data variable in shp for the bubble map that specifies the colors ofthe bubbles. If neither bubble.size nor bubble.col is specified, no bubblemap is drawn. Only applicable when shp is type 1, 2, or 3 (see above).

    dot.col name of the data variable in shp for the dot map that specifies the colors of thedots.

  • 26 qtm

    text Name of the data variable that contains the text labels. Only applicable whenshp is type 1, 2, or 3 (see above).

    text.size Font size of the text labels. Either a constant value, or the name of a numericdata variable. Only applicable when shp is type 1, 2, or 3 (see above).

    text.col name of the data variable in shp for the that specifies the colors of the text labels.Only applicable when shp is type 1, 2, or 3 (see above).

    line.lwd either a line width or a name of the data variable that specifies the line width.Only applicable when shp is type 3 (see above).

    line.col either a line color or a name of the data variable that specifies the line colors.Only applicable when shp is type 3 (see above).

    raster either a color or a name of the data variable that specifices the raster colors.Only applicable when shp is type 4, 5, or 6 (see above).

    borders color of the polygon borders. Use NA to omit the borders.

    scale numeric value that serves as the global scale parameter. All font sizes, bubblesizes, border widths, and line widths are controled by this value. The param-eters bubble.size, text.size, and line.lwd can be scaled seperately withrespectively bubble.scale, text.scale, and line.scale.

    title main title. For legend titles, use X.style, where X is layer name (see ...).

    projection character that determines the projection. Either a PROJ.4 character string or ashortcut. See get_proj4 for a list of shortcut values. By default, the projec-tion is used that is defined in the shp object itself, which can be obtained withget_projection.

    format tm_layout wrapper used for format. Currently available in tmap: "World", "Eu-rope", "NLD", "World_wide", "Europe_wide", "NLD_wide". Own wrapperscan be used as well (see details).

    style tm_layout wrapper used for style. Available in tmap: "bw", "classic". Ownwrappers can be used as well (see details).

    basemaps basemaps for the view mode. See tm_view

    ... arguments passed on to the tm_* functions. If an argument name is not uniquefor a particular tm_ function, then it should be prefixed with the function namewithout "tm_". For instance, style is an argument of tm_fill, tm_bubbles,and tm_lines. Therefore, in order to define the style for a choropleth, itsarugment name should be fill.style.

    Details

    This function is a convenient wrapper of the main plotting method of stacking tmap-elements. Thefirst argument is a shape object (normally specified by tm_shape). The next arguments, from fillto raster, are the aesthetics from the main layers. The remaining arguments are related to the maplayout. Any argument from any main layer can be specified (see ...). It is also possible to stacktmap-elements on a qtm plot. See examples.

    For format any character value, say "xxx" can be used if the wrapper function "tm_format_xxx"exists. The same applies for the arguments colors, and style.

  • read_GPX 27

    Value

    tmap-element

    See Also

    vignette("tmap-nutshell")

    Examples

    data(World, rivers, metro)

    # just the mapqtm(World)

    # choroplethqtm(World, fill = "economy", format="World", style="col_blind")

    qtm(World, fill="HPI", fill.n=9, fill.palette="div", fill.auto.palette.mapping=FALSE,fill.title="Happy Planet Index", format="World", style="gray")

    # bubble mapqtm(World, borders = NULL) + qtm(metro, bubble.size = "pop2010",

    bubble.title.size="Metropolitan Areas", bubble.scale=.5, format = "World")

    # TIP: check out these examples in view mode, enabled with tmap_mode("view")

    read_GPX Read GPX file

    Description

    Read a GPX file. By default, it reads all possible GPX layers, and only returns shapes for layersthat have any features.

    Usage

    read_GPX(file, layers = c("waypoints", "tracks", "routes", "track_points","route_points"))

    Arguments

    file a GPX filename (including directory)

    layers vector of GPX layers. Possible options are "waypoints", "tracks", "routes","track_points", "route_points". By dedault, all those layers are read.

    ../doc/tmap-nutshell.html

  • 28 read_osm

    Value

    for each defiend layer, a shape is returned (only if the layer has any features). If only one layeris defined, the corresponding shape is returned. If more than one layer is defined, a list of shapeobjects, one for each layer, is returned.

    Examples

    ### Demo to visualise the route of the Amstel Gold Race, a professional cycling race## Not run:tmpdir

  • read_osm 29

    osm_poly(query)

    osm_line(query)

    osm_point(query)

    Arguments

    x shape, bounding box, or osmar object. If a shape (from class Spatial orRaster) is specified, the bounding box of it is taken. See also ... (otherarguments). If a bounding box is specified, it should be in longitude latitudecoordinates.

    raster logical that determines whether a raster or vector shapes are returned. In the lat-ter case, specify the vector selections (see argument ...). By default, raster=TRUEif no vector selections are made, and raster=FALSE otherwise.

    zoom passed on to openmap. Only applicable when raster=TRUE.

    type passed on to openmap Only applicable when raster=TRUE.

    minNumTiles passed on to openmap Only applicable when raster=TRUE.

    mergeTiles passed on to openmap Only applicable when raster=TRUE.

    ... arguments passed on to bb in case x is a shape, or arguments that specifypolygons, lines, and/or points queries, created with osm_poly, osm_line, andosm_point respectively.

    query query to select polygons, lines, or points. Currently, two formats are sup-ported: 1) key, 2) key=value. See http://wiki.openstreetmap.org/wiki/Map_Features for Open Street Map keys and values.

    Value

    The output of read_osm is a SpatialGridDataFrame if raster=TRUE, and otherwise a named listof SpatialPolygonsDataFrame, SpatialLinesDataFrame, and/or SpatialPointsDataFrame ob-jects. The names of this list are the names of arguments defined at ....

    Examples

    ## Not run:#### Choropleth with OSM background

    # load Netherlands shapedata(NLD_muni)

    # read OSM raster dataosm_NLD

  • 30 read_shape

    tm_polygons("population", convert2density=TRUE, style="kmeans", alpha=.7, palette="Purples")

    #### A close look at the building of Statistics Netherlands in Heerlen

    # create a bounding box around the CBS (Statistics Netherlands) buildingCBS_bb

  • read_shape 31

    Arguments

    file a shape file name (including directory)current.projection

    the current projection of the shape object, if it is missing in the shape file.It should be either a PROJ.4 character string (see http://trac.osgeo.org/proj/), of one of the following shortcuts:

    "longlat" Not really a projection, but a plot of the longitude-latitude coordi-nates (WGS84 datum).

    "wintri" Winkel Tripel (1921). Popular projection that is useful in worldmaps. It is the standard of world maps made by the National GeographicSociety. Type: compromise

    "robin" Robinson (1963). Another popular projection for world maps. Type:compromise

    "eck4" Eckert IV (1906). Projection useful for world maps. Area sizes arepreserved, which makes it particularly useful for truthful choropleths. Type:equal-area

    "hd" Hobo-Dyer (2002). Another projection useful for world maps in whicharea sizes are preserved. Type: equal-area

    "gall" Gall (Peters) (1855). Another projection useful for world maps inwhich area sizes are preserved. Type: equal-area

    "merc" Mercator (1569). Projection in which shapes are locally preserved.However, areas close to the poles are inflated. Google Maps uses a closevariant of the Mercator. Type: conformal

    "utmXX(s)" Universal Transverse Mercator. Set of 60 projections where eachprojection is a traverse mercator optimized for a 6 degree longitude range.These ranges are called UTM zones. Zone 01 covers -180 to -174 degrees(West) and zone 60 174 to 180 east. Replace XX in the character stringwith the zone number. For southern hemisphere, add "s". So, for instance,the Netherlands is "utm31" and New Zealand is "utm59s"

    "mill" Miller (1942). Projetion based on Mercator, in which poles are dis-played. Type: compromise

    "eqc0" Equirectangular (120). Projection in which distances along meridiansare conserved. The equator is the standard parallel. Also known as PlateCarr\’ee. Type: equidistant

    "eqc30" Equirectangular (120). Projection in which distances along meridiansare conserved. The latitude of 30 is the standard parallel. Type: equidistant

    "eqc45" Equirectangular (120). Projection in which distances along meridiansare conserved. The latitude of 45 is the standard parallel. Also known asGall isographic. Type: equidistant

    "rd" Rijksdriehoekstelsel. Triangulation coordinate system used in the Nether-lands.

    See http://en.wikipedia.org/wiki/List_of_map_projections for a overviewof projections. Use set_projection to reproject the shape object.

    ... other parameters, such as stringsAsFactors, are passed on to readOGR

    http://trac.osgeo.org/proj/http://trac.osgeo.org/proj/http://en.wikipedia.org/wiki/List_of_map_projections

  • 32 sample_dots

    Details

    This function is a convenient wrapper of rgdal’s readOGR. It is possible to set the current projection,if it is undefined in the shape file. If a reprojection is required, use set_projection.

    For the Netherlands: often, the Dutch Rijksdriehoekstelsel (Dutch National Grid) projection is pro-vided in the shape file without proper datum shift parameters to wgs84. This functions automaticallyadds these parameters. See http://www.qgis.nl/2011/12/05/epsg28992-of-rijksdriehoekstelsel-verschuiving/(in Dutch) for details.

    Value

    shape object

    rivers Spatial data of rivers

    Description

    Spatial data of rivers, of class SpatialLinesDataFrame

    Usage

    data(rivers)

    Source

    http://www.naturalearthdata.com

    sample_dots Sample dots from spatial polygons

    Description

    Sample dots from spatial polygons according to a spatial distribution of a population. The popula-tion may consist of classes. The output, a SpatialPointsDataFrame, can be used to create a dot map(see tm_dots), where the dots are colored according to the classes.

    Usage

    sample_dots(shp, vars = NULL, convert2density = FALSE, nrow = NA,ncol = NA, N = 250000, npop = NA, n = 10000, w = NA,shp.id = NULL, var.name = "class", var.labels = vars, unit = "km",unit.size = 1000, randomize = TRUE, output = c("points", "grid"), ...)

    http://www.qgis.nl/2011/12/05/epsg28992-of-rijksdriehoekstelsel-verschuiving/http://www.naturalearthdata.com

  • sample_dots 33

    Arguments

    shp A shape object, more specifically, a SpatialPolygonsDataFrame.

    vars Names of one or more variables that are contained in shp. If vars is not pro-vided, the dots are sampled uniformly. If vars consists of one variable name,the dots are sampled according to the distribution of the corresponding variable.If vars consist of more than one variable names, then the dots are sampled ac-cording to the distributions of those variables. A categorical variable is addedthat contains the distrubtion classes (see var.name).

    convert2density

    Should the variables be converted to density values? Density values are used forthe sampling algorithm, so use TRUE when the values are absolute counts.

    nrow Number of grid rows

    ncol Number of grid colums

    N Number of grid points

    npop Population total. If NA, it is recontructed from the data. If density values arespecified, the population total is approximated using the polygon areas (see alsounit and unit.size).

    n Number of sampled dots

    w Number of population units per dot. It is the population total divided by n. Ifspecified, n is calculated accordingly.

    shp.id Name of the variable of shp that contains the polygon identifying numbers ornames.

    var.name Name of the variable that will be created to store the classes. The classes aredefined by vars, and the labels can be configured with var.labels.

    var.labels Labels of the classes (see var.name).

    unit Unit, see calc_densities. Needed to relate npop to w, if they are not bothspecified.

    unit.size Unit size, see calc_densities. Needed to relate npop to w, if they are not bothspecified.

    randomize should the order of sampled dots be randomized? The dots are sampled class-wise (specified by vars). If this order is not randomized (so if randomize=FALSE),then the dots from the last class will be drawn on top, which may introduce a per-ception bias. By default randomize=TRUE, so the sampled dots are randomizedto prevent this bias.

    output format of the output: use "points" for spatial points, and "grid" for a spatialgrid.

    ... other arguments passed on to calc_densities and approx_areas

    Details

    The sampling algoritm is the following: TO DO

  • 34 save_tmap

    Examples

    ## Not run:data(World)World_dots

  • sbind 35

    insets_vp viewport of an inset map, or a list of viewports of multiple inset maps. Thenumber of viewports should be equal to the number of tmap objects specifiedwith insets_tm.

    verbose should information messages be returned?

    ... arguments passed on to device functions or to saveWidget

    Examples

    ## Not run:data(NLD_muni, NLD_prov)m

  • 36 set_projection

    Arguments

    ... shape objects. Each shape object is one of1. SpatialPolygons(DataFrame)2. SpatialPoints(DataFrame)3. SpatialLines(DataFrame)

    Value

    shape object

    set_projection Set and get the map projection

    Description

    The function set_projection sets the projection of a shape file. It is a convenient wrapper ofspTransform and projectRaster with shortcuts for commonly used projections. The projectioncan also be set directly in the plot call with tm_shape. This function is also used to set the currentprojection information if this is missing. The function get_projection is used to get the projectioninformation.

    Usage

    set_projection(shp, projection = NULL, current.projection = NULL,overwrite.current.projection = FALSE)

    get_projection(shp)

    Arguments

    shp shape object of class Spatial or Raster (see details).projection character that determines the new projection. Either a PROJ.4 character string

    or a shortcut. See get_proj4 for a list of shortcut values. This argument is onlyused to transform the shp. Use current.projection to specify the currentprojection of shp.

    current.projection

    the current projection of shp. Only use this if the current projection is missingor wrong.

    overwrite.current.projection

    logical that determines whether the current projection is overwritten if it alreadyhas a projection that is different.

    Details

    For raster objects, the projection method is based on the type of data. For numeric layers, thebilinear method is used, and for categorical layers the nearest neighbor. See projectRaster fordetails.

  • smooth_map 37

    Value

    set_projection returns a (transformed) shape object with updated projection information. get_projectionreturns the PROJ.4 character string of shp.

    smooth_map Create a smooth map in various formats: smooth raster, contour lines,and dasymetric polygons.

    Description

    Create contour lines (isolines) from a shape object. To make the iso lines smooth, a 2D kernaldensity estimator is applied on the shape object. These lines are used to draw an isopleth. Also, thepolygons between the countour lines are returned. They can be used to create a dasymetric map.

    Usage

    smooth_map(shp, var = NULL, nrow = NA, ncol = NA, N = 250000,unit = "km", unit.size = 1000, smooth.raster = TRUE, nlevels = 5,style = ifelse(is.null(breaks), "pretty", "fixed"), breaks = NULL,bandwidth = NA, cover.type = NA, cover = NULL, cover.threshold = 0.6,weight = 1, extracting.method = "full", buffer.width = NA,to.Raster = FALSE)

    Arguments

    shp shape object of class Spatial or Raster. Spatial points, polygons, and gridsare supported. Spatial lines are not.

    var variable name. Not needed for SpatialPoints. If missing, the first variablename is taken.

    nrow number of rows in the raster that is used to smooth the shape object. Onlyapplicable if shp is not a SpatialGrid(DataFrame) or Raster

    ncol number of rows in the raster that is used to smooth the shape object. Onlyapplicable if shp is not a SpatialGrid(DataFrame) or Raster

    N preferred number of points in the raster that is used to smooth the shape object.Only applicable if shp is not a SpatialGrid(DataFrame) or Raster

    unit unit specification. Needed when calculating density values. When set to NA, thedensities values are based on the dimensions of the raster (defined by nrow andncol). See also unit.size.

    unit.size size of the unit in terms of coordinate units. The coordinate system of many pro-jections is approximately in meters while thematic maps typically range manykilometers, so by default unit="km" and unit.size=1000 (meaning 1 kilome-ter equals 1000 coordinate units).

    smooth.raster logical that determines whether 2D kernel density smoothing is applied to theraster shape object. Not applicable when shp is a SpatialPoints object.

  • 38 smooth_map

    nlevels preferred number of levels

    style method to cut the color scale: e.g. "fixed", "equal", "pretty", "quantile", or"kmeans". See the details in classIntervals.

    breaks in case style=="fixed", breaks should be specified

    bandwidth single numeric value or vector of two numeric values that specifiy the bandwidthof the kernal density estimator. By default, it is 1/50th of the shortest side in units(specified with unit.size).

    cover.type character value that specifies the type of raster cover, in other words, how theboundaries are specified. Options: "original" uses the same boundaries asshp (default for polygons), "smooth" calculates a smooth boundary based onthe 2D kernal density (determined by smooth_raster_cover), "rect" uses thebounding box of shp as boundaries (default for spatial points and grids).

    cover SpatialPolygons shape that determines the covered area in which the contourlines are placed. If specified, cover.type is ignored.

    cover.threshold

    numeric value between 0 and 1 that determines which part of the estimated 2Dkernal density is returned as cover. Only applicable when cover.type="smooth".

    weight single number that specifies the weight of a single point. Only applicable if shpis a SpatialPoints object.

    extracting.method

    Method of how coordinates are extracted from the dasymetric polygons. Op-tions are: "full" (default), "grid", and "single". See details. For the slowestmethod "full", extract is used. For "grid", points on a grid layout are se-lected that intersect with the polygon. For "simple", a simple point is generatedwith gPointOnSurface.

    buffer.width Buffer width of the iso lines to cut dasymetric polygons. Should be small enoughto let the polygons touch each other without space in between. However, too lowvalues may cause geometric errors.

    to.Raster should the "raster" output (see output) be a RasterLayer? By default, it isreturned as a SpatialGridDataFrame

    Details

    For the estimation of the 2D kernal density, code is borrowed from bkde2D. This implementionis slightly different: bkde2D takes point coordinates and applies linear binning, whereas in thisfunction, the data is already binned, with values 1 if the values of var are not missing and 0 ifvalues of var are missing.

    Value

    List with the following items:

    "raster" A smooth raster, which is either a SpatialGridDataFrame or a RasterLayer (seeto.Raster)

    "iso" Contour lines, which is a SpatialLinesDataFrame

    "dasy" Dasymetric polygons, which is a SpatialPolygonsDataFrame

  • smooth_map 39

    "bbox" Bounding box of the used raster

    "ncol" Number of rows in the raster

    "nrow" Number of columns in the raster

    Examples

    ###################################### Already smoothed raster####################################vol

  • 40 smooth_map

    # assign to World shapeWorld$pop_metro

  • smooth_raster_cover 41

    smooth_raster_cover Get a smoothed cover of a raster object

    Description

    Get a smoothed cover of a raster object. From all non-missing values of a raster object, a 2D kernaldensity is applied. The output is a SpatialPolygons object. Used by smooth_map.

    Usage

    smooth_raster_cover(shp, var = NA, bandwidth = NA, threshold = 0.6,output = "SpatialPolygons")

    Arguments

    shp raster object, from either SpatialGrid(DataFrame) or Raster class.

    var name of the variable from which missing values are flagged. If unspecified, thefirst variable will be taken.

    bandwidth single numeric value or vector of two numeric values that specifiy the bandwidthof the kernal density estimator. See details.

    threshold numeric value between 0 and 1 that determines which part of the estimated 2Dkernal density is returned as cover.

    output class of the returned object. One of: SpatialPolygons, SpatialLines, SpatialGridDataFrame,or RasterLayer. A vector of class names results in a list of output objects.

    Details

    For the estimation of the 2D kernal density, code is borrowed from bkde2D. This implementionis slightly different: bkde2D takes point coordinates and applies linear binning, whereas in thisfunction, the data is already binned, with values 1 if the values of var are not missing and 0 ifvalues of var are missing.

    split.SpatialPolygons Divide into multiple shape objects

    Description

    Divide a shape object into multiple objects.

  • 42 style_catalogue

    Usage

    ## S3 method for class 'SpatialPolygons'split(x, f, drop = FALSE, ...)

    ## S3 method for class 'SpatialPoints'split(x, f, drop = FALSE, ...)

    ## S3 method for class 'SpatialLines'split(x, f, drop = FALSE, ...)

    Arguments

    x shape object, which is one of

    1. SpatialPolygons(DataFrame)

    2. SpatialPoints(DataFrame)

    3. SpatialLines(DataFrame)

    f factor to split x

    drop unused factor levels are dropped

    ... other arguments (not used)

    Value

    List of shape objects.

    style_catalogue Create a style catalogue

    Description

    Create a style catalogue for each predefined tmap style. The result is a set of png images, one foreach style.

    Usage

    style_catalogue(path = "./tmap_style_previews", styles = NA,include.global.styles = TRUE)

    style_catalog(path = "./tmap_style_previews", styles = NA,include.global.styles = TRUE)

  • tmap-element 43

    Arguments

    path path where the png images are stored

    styles vector of tm_style_XXX function names. By default, it contains all styles thatare included in tmap, and, if include.global.styles=TRUE, also the user de-fined tm_style_XXX function names.

    include.global.styles

    See above

    tmap-element tmap element

    Description

    Building block for drawing thematic maps. All element functions have the prefix tm_.

    Details

    The fundamental, and hence required element is

    • tm_shape that specifies the shape object, and also specifies the projection and bounding box

    The elements that serve as aesthetics layers are

    • tm_fill to fill the polygons

    • tm_borders to draw polygon borders

    • tm_polygons to draw polygons (it is a combination of tm_fill and tm_borders)

    • tm_bubbles to draw bubbles

    • tm_lines to draw lines

    • tm_text to add text annotations

    • tm_raster to draw a raster

    The layers can be stacked by simply adding them with the + symbol. The combination of theelements described above form one group. Multiple groups can be stacked. Each group should startwith tm_shape.

    The attribute elements are

    • tm_grid to specify coordinate grid lines

    • tm_credits to add a credits/acknowledgements text label

    • tm_scale_bar to add a measurement scale bar

    • tm_compass to add a map compass

    The element tm_facets specifies facets (small multiples). The element tm_layout is used tochange the layout of the map.

  • 44 tmap_leaflet

    See Also

    vignette("tmap-nutshell")

    vignette("tmap-modes")

    The examples in each of the element functions

    tmap_leaflet Create a leaflet widget from a tmap object

    Description

    Create a leaflet widget from a tmap object. An interactive map (see tmap_mode) is an automaticallygenerated leaflet widget. With this function, this leaflet widget is obtained, which can then bechanged or extended by using leaflet’s own methods.

    Usage

    tmap_leaflet(x, mode = "view", show = FALSE, ...)

    Arguments

    x tmap object. A tmap object is created with qtm or by stacking tmap-elements.

    mode the mode of tmap, which is set to "view" in order to obtain the leaflet object.See tmap_mode for details.

    show should the leaflet map be shown? FALSE by default

    ... arguments passed on to print.tmap

    Value

    leaflet object

    See Also

    tmap_mode, tm_view, print.tmap

    Examples

    # world choropleth/bubble map of the worlddata(World, metro)metro$growth

  • tmap_mode 45

    tm_layout(legend.bg.color = "grey90", legend.bg.alpha=.5, legend.frame=TRUE)

    lf % leaflet::addMarkers(2.2945, 48.8582, popup = "Eiffel tower")

    tmap_mode Set tmap mode to static plotting or interactive viewing

    Description

    Set tmap mode to static plotting or interactive viewing. The global option tmap.mode determinesthe whether thematic maps are plot in the graphics device, or shown as an interactive leaflet map.The function tmap_mode is a wrapper to set this global option. The convenient function ttm is atoggle switch between the two modes. Tip: use tmap_mode in scripts and ttm in the console.

    Usage

    tmap_mode(mode = c("plot", "view"))

    ttm()

    Arguments

    mode one of

    "plot" Thematic maps are shown in the graphics device. This is the defaultmode, and supports all tmap’s features, such as small multiples (see tm_facets)and extensive layout settings (see tm_layout). It is recommended for sav-ing static maps (see save_tmap).

    "view" Thematic maps are viewed interactively in the web browser or RStu-dio’s Viewer pane. Maps are fully interactive with tiles from OpenStreetMapor other map providers. See tm_view for options related to the "view"mode. This mode generates a leaflet widget, which can also be directlyobtained with tmap_leaflet. With RMarkdown, it is possible to publishit to an HTML page. There are a couple of contraints in comparison to"plot":

    • The map is always projected accoring to the Web Mercator projection.Although this projection is the de facto standard for interactive web-based mapping, it lacks the equal-area property, which is importantfor many thematic maps, especially choropleths (see examples fromtm_shape).

  • 46 tmap_mode

    • Small multiples are not supported• The legend cannot be made for aesthetics regarding size, which are

    bubble size and line width.• Text labels are not supported (yet)• The layout options set with tm_layout) regarding map format are not

    used. However, the styling options still apply.

    Value

    the mode before changing

    See Also

    vignette("tmap-modes"), tm_view for viewing options, and tmap_leaflet for obtaining a leafletwidget

    Examples

    # world choropleth/bubble map of the worlddata(World, metro)metro$growth

  • tmap_style 47

    title = "Population (per km^2)", id = "name") +tm_borders("grey25", alpha=.5) +tm_shape(NLD_prov) +tm_borders("grey40", lwd=2)

    # restore current modetmap_mode(current.mode)

    tmap_style Set the default tmap style

    Description

    Set the default tmap style, which is contained in the global option tmap.style.

    Usage

    tmap_style(style)

    Arguments

    style name of the style. The function tm_style_ should exist and be a wrap-per of tm_layout. The default style when loading the package is "white",which corresponds to the function tm_style_white.

    Value

    the style before changing

    See Also

    tm_layout for predefined styles, and style_catalogue to create a style catelogue of all availablestyles.

    Examples

    data(World)

    current.style

  • 48 tm_bubbles

    tm_bubbles Draw bubbles or dots

    Description

    Creates a tmap-element that draws bubbles or small dots. Both colors and sizes of the bubbles canbe mapped to data variables.

    Usage

    tm_bubbles(size = 0.2, col = NA, alpha = NA, border.col = NA,border.lwd = 1, border.alpha = NA, scale = 1, perceptual = FALSE,size.lim = NA, sizes.legend = NULL, sizes.legend.labels = NULL, n = 5,style = ifelse(is.null(breaks), "pretty", "fixed"), breaks = NULL,palette = NULL, labels = NULL, auto.palette.mapping = TRUE,contrast = NA, max.categories = 12, colorNA = NA, textNA = "Missing",showNA = NA, jitter = 0, xmod = 0, ymod = 0, title.size = NA,title.col = NA, legend.size.show = TRUE, legend.col.show = TRUE,legend.format = list(), legend.size.is.portrait = FALSE,legend.col.is.portrait = TRUE, legend.hist = FALSE,legend.hist.title = NA, legend.size.z = NA, legend.col.z = NA,legend.hist.z = NA, id = NA)

    tm_dots(col = NA, size = 0.02, title = NA, legend.show = TRUE,legend.is.portrait = TRUE, legend.z = NA, ...)

    Arguments

    size a single value or a shp data variable that determines the bubble sizes. The refer-ence value size=1 corresponds to the area of bubbles that have the same heightas one line of text. If a data variable is provided, the bubble sizes are scaled pro-portionally (or perceptually, see perceptual) where the largest bubble will getsize=1. If multiple values are specified, small multiples are drawn (see details).

    col color(s) of the bubble. Either a color (vector), or categorical variable name(s).If multiple values are specified, small multiples are drawn (see details).

    alpha transparency number between 0 (totally transparent) and 1 (not transparent). Bydefault, the alpha value of the col is used (normally 1).

    border.col color of the bubble borders.

    border.lwd line width of the bubble borders. If NA (default), no bubble borders are drawn.

    border.alpha transparency number, regarding the bubble borders, between 0 (totally trans-parent) and 1 (not transparent). By default, the alpha value of the col is used(normally 1).

    scale bubble size multiplier number.

  • tm_bubbles 49

    perceptual logical that determines whether bubbles are scales with a perceptually (TRUE)or mathematically (FALSE, default value). The perceived area of larger bubblesis often underestimated. Flannery (1971) experimentally derived a method tocompensate this, which is enabled by this argument.

    size.lim vector of two limit values of the size variable. Only bubbles are drawn whosevalue is greater than or equal to the first value. Bubbles whose values exceed thesecond value are drawn at the size of the second value. Only applicable whensize is the name of a numeric variable of shp

    sizes.legend vector of bubble sizes that are shown in the legend. By default, this is determinedautomatically.

    sizes.legend.labels

    vector of labels for that correspond to sizes.legend.

    n preferred number of color scale classes. Only applicable when col is a numericvariable name.

    style method to process the color scale when col is a numeric variable. Discrete op-tions are "cat", "fixed", "sd", "equal", "pretty", "quantile", "kmeans","hclust", "bclust", "fisher", and "jenks". A numeric variable is processedas a categorial variable when using "cat", i.e. each unique value will corre-spond to a distinct category. For the other discrete options, see the details inclassIntervals. Continuous options are "cont" and "order". The former mapsthe values of col to a smooth gradient, whereas the latter maps the order of val-ues of col to a smooth gradient. They are the continuous variants of respectivelythe discrete methods "equal" and quantile".

    breaks in case style=="fixed", breaks should be specified

    palette color palette (see RColorBrewer::display.brewer.all) for the bubbles. Onlywhen col is set to a variable. The default palette is taken from tm_layout’s ar-gument aes.palette.

    labels labels of the classesauto.palette.mapping

    When diverging colour palettes are used (i.e. "RdBu") this method automaticallymaps colors to values such that the middle colors (mostly white or yellow) areassigned to values of 0, and the two sides of the color palette are assigned tonegative respectively positive values. When categorical color palettes are used,this method stretches the palette is there are more levels than colors.

    contrast vector of two numbers that determine the range that is used for sequential anddiverging palettes (applicable when auto.palette.mapping=TRUE). Both num-bers should be between 0 and 1. The first number determines where the palettebegins, and the second number where it ends. For sequential palettes, 0 meansthe brightest color, and 1 the darkest color. For diverging palettes, 0 means themiddle color, and 1 both extremes. If only one number is provided, this numberis interpreted as the endpoint (with 0 taken as the start).

    max.categories in case col is the name of a categorical variable, this value determines howmany categories (levels) it can have maximally. If the number of levels is higherthan max.categories and auto.palette.mapping is FALSE, then levels arecombined.

  • 50 tm_bubbles

    colorNA colour for missing values. Use NULL for transparency.

    textNA text used for missing values.

    showNA logical that determines whether missing values are named in the legend. Bydefault (NA), this depends on the presence of missing values.

    jitter number that determines the amount of jittering, i.e. the random noise added tothe position of the bubbles. 0 means no jittering is applied, any positive numbermeans that the random noise has a standard deviation of jitter times the heightof one line of text line.

    xmod horizontal position modification of the bubbles, in terms of the height of oneline of text. Either a single number for all polygons, or a numeric variable inthe shape data specifying a number for each polygon. Together with ymod, itdetermines position modification of the bubbles. See also jitter for randomposition modifications. In most coordinate systems (projections), the origin islocated at the bottom left, so negative xmod move the bubbles to the left, andnegative ymod values to the bottom.

    ymod vertical position modification. See xmod.

    title.size title of the legend element regarding the bubble sizes

    title.col title of the legend element regarding the bubble colorslegend.size.show

    logical that determines whether the legend for the bubble sizes is shownlegend.col.show

    logical that determines whether the legend for the bubble colors is shown

    legend.format list of formatting options for the legend numbers. Only applicable if labels isundefined. Parameters are:

    scientific Should the labels be formatted scientically? If so, square brackets areused, and the format of the numbers is "g". Otherwise, format="f", andtext.separator, text.less.than, and text.or.more are used. Also,the numbers are automatically rounded to millions or billions if applicable.

    format By default, "f", i.e. the standard notation xxx.xxx, is used. If scientific=TRUEthen "g", which means that numbers are formatted scientically, i.e. n.dddE+nnif needed to save space.

    digits Number of digits after the decimal point if format="f", and the numberof significant digits otherwise.

    text.separator Character string to use to separate numbers in the legend (de-fault: "to").

    text.less.than Character string to use to translate "Less than" (which is the de-fault).

    text.or.more Character string to use to translate "or more" (which is the de-fault).

    ... Other arguments passed on to formatClegend.size.is.portrait

    logical that determines whether the legend element regarding the bubble sizes isin portrait mode (TRUE) or landscape (FALSE)

  • tm_bubbles 51

    legend.col.is.portrait

    logical that determines whether the legend element regarding the bubble colorsis in portrait mode (TRUE) or landscape (FALSE)

    legend.hist logical that determines whether a histogram is shown regarding the bubble col-ors

    legend.hist.title

    title for the histogram. By default, one title is used for both the histogram andthe normal legend for bubble colors.

    legend.size.z index value that determines the position of the legend element regarding thebubble sizes with respect to other legend elements. The legend elements arestacked according to their z values. The legend element with the lowest z valueis placed on top.

    legend.col.z index value that determines the position of the legend element regarding thebubble colors. (See legend.size.z)

    legend.hist.z index value that determines the position of the histogram legend element. (Seelegend.size.z)

    id name of the data variable that specifies the indices of the bubbles. Only used for"view" mode (see tmap_mode).

    title shortcut for title.col for tm_dots

    legend.show shortcut for legend.col.show for tm_dotslegend.is.portrait

    shortcut for legend.col.is.portrait for tm_dots

    legend.z shortcut for legend.col.z shortcut for tm_dots

    ... arguments passed on to tm_bubbles

    Details

    Small multiples can be drawn in two ways: either by specifying the by argument in tm_facets, orby defining multiple variables in the aesthetic arguments. The aesthetic arguments of tm_bubblesare size and col. In the latter case, the arguments, except for the ones starting with legend., canbe specified for small multiples as follows. If the argument normally only takes a single value, suchas n, then a vector of those values can be specified, one for each small multiple. If the argumentnormally can take a vector, such as palette, then a list of those vectors (or values) can be specified,one for each small multiple.

    Value

    tmap-element

    References

    Flannery J (1971). The Relative Effectiveness of Some Common Graduated Point Symbols in thePresentation of Quantitative Data. Canadian Cartographer, 8 (2), 96-109.

    See Also

    vignette("tmap-nutshell")

    ../doc/tmap-nutshell.html

  • 52 tm_compass

    Examples

    data(World, metro)metro$growth

  • tm_credits 53

    show.labels number that specifies which labels are shown: 0 means no labels, 1 (default)means only north, 2 means all four cardinal directions, and 3 means the fourcardinal directions and the four intercardinal directions (e.g. north-east).

    cardinal.directions

    labels that are used for the cardinal directions north, east, south, and west.

    text.color color of the text. By default equal to the argument attr.color of tm_layout.

    color.dark color of the dark parts of the compass, typically (and by default) black.

    color.light color of the light parts of the compass, typically (and by default) white.

    lwd line width of the compass

    position position of the text. Vector of two values, specifing the x and y coordinates.Either this vector contains "left", "LEFT", "center", "right", or "RIGHT" for thefirst value and "top", "TOP", "center", "bottom", or "BOTTOM" for the secondvalue, or this vector contains two numeric values between 0 and 1 that specifiesthe x and y value of the left bottom corner of the compass. The uppercase valuescorrespond to the position without margins (so tighter to the frame). The defaultvalue is controlled by the argument "attr.position" of tm_layout.

    Examples

    current.mode

  • 54 tm_credits

    Arguments

    text text. Multiple lines can be created with the line break symbol "\n". Facets canhave different texts: in that case a vector of characters is required. Use "" toomit the credits for specific facets.

    size relative text size

    col color of the text. By default equal to the argument attr.color of tm_layout.

    alpha transparency number between 0 (totally transparent) and 1 (not transparent). Bydefault, the alpha value of col is used (normally 1).

    align horizontal alignment: "left" (default), "center", or "right". Only applicableif text contains multiple lines

    bg.color background color for the text

    bg.alpha Transparency number between 0 (totally transparent) and 1 (not transparent).By default, the alpha value of the bg.color is used (normally 1).

    fontface font face of the text. By default, determined by the fontface argument of tm_layout.

    fontfamily font family of the text. By default, determined by the fontfamily argument oftm_layout.

    position position of the text. Vector of two values, specifing the x and y coordinates.Either this vector contains "left", "LEFT", "center", "right", or "RIGHT" for thefirst value and "top", "TOP", "center", "bottom", or "BOTTOM" for the secondvalue, or this vector contains two numeric values between 0 and 1 that specifiesthe x and y value of the center of the text. The uppercase values correspondto the position without margins (so tighter to the frame). The default value iscontrolled by the argument "attr.position" of tm_layout.

    See Also

    tm_xlab

    Examples

    current.mode

  • tm_facets 55

    tm_facets Small multiples

    Description

    Creates a tmap-element that specifies facets (small multiples). Small multiples can be created intwo ways: 1) by specifying the by argument with one or two variable names, by which the datais grouped, 2) by specifying multiple variable names in any of the aesthetic argument of the layerfunctions (for instance, the argument col in tm_fill). This function further specifies the facets, forinstance number of rows and columns, and whether the coordinate and scales are fixed or free (i.e.independent of each other).

    Usage

    tm_facets(by = NULL, ncol = NULL, nrow = NULL, free.coords = FALSE,drop.units = free.coords, drop.empty.facets = TRUE, showNA = NA,textNA = "Missing", free.scales = is.null(by),free.scales.fill = free.scales, free.scales.bubble.size = free.scales,free.scales.bubble.col = free.scales, free.scales.text.size = free.scales,free.scales.text.col = free.scales, free.scales.line.col = free.scales,free.scales.line.lwd = free.scales, free.scales.raster = free.scales,inside.original.bbox = FALSE, scale.factor = 2,drop.shapes = drop.units)

    Arguments

    by data variable name by which the data is split, or a vector of two variable namesto split the data by two variables (where the first is used for the rows and thesecond for the columns).

    ncol number of columns of the small multiples grid. Not applicable if by containstwo variable names.

    nrow number of rows of the small multiples grid. Not applicable if by contains twovariable names.

    free.coords logical. If the by argument is specified, should each map has its own coordinateranges?

    drop.units logical. If the by argument is specified, should non-selected spatial units bedropped? If FALSE, they are plotted where mapped aesthetics are regared asmissing values. By default, TRUE if free.coords=TRUE. Not applicable forraster shapes.

    drop.empty.facets

    logical. If the by argument is specified, should empty facets be dropped? Emptyfacets occur when the by-variable contains unused levels. When TRUE and twoby-variables are specified, empty rows and colums are dropped.

  • 56 tm_facets

    showNA If the by argument is specified, should missing values of the by-variable beshown in a facet? If two by-variables are specified, should missing values beshown in an additional row and column? If NA, missing values only are shownif they exist. Similar to the useNA argument of table, where TRUE, FALSE, andNA correspond to "always", "no", and "ifany" respectively.

    textNA text used for facets of missing values.

    free.scales logical. Should all scales of the plotted data variables be free, i.e. independentof each other? Possible data variables are color from tm_fill, color and sizefrom tm_bubbles and line color from tm_lines.

    free.scales.fill

    logical. Should the color scale for the choropleth be free?

    free.scales.bubble.size

    logical. Should the bubble size scale for the bubble map be free?

    free.scales.bubble.col

    logical. Should the color scale for the bubble map be free?

    free.scales.text.size

    logical. Should the text size scale be free?

    free.scales.text.col

    logical. Should the text color scale be free?

    free.scales.line.col

    Should the line color scale be free?free.scales.line.lwd

    Should the line width scale be free?free.scales.raster

    Should the color scale for raster layers be free?

    inside.original.bbox

    If free.coords, should the bounding box of each small multiple be inside theoriginal bounding box?

    scale.factor Number that determines how the elements (e.g. font sizes, bubble sizes, linewidths) of the small multiples are scaled in relation to the scaling factor of theshapes. The elements are scaled to the scale.factorth root of the scaling factorof the shapes. So, for scale.factor=1, they are scaled proportional to thescaling of the shapes. Since elements, especially text, are often too small toread, a higher value is recommended. By default, scale.factor=2.

    drop.shapes deprecated: renamed to drop.units

    Value

    tmap-element

    See Also

    vignette("tmap-nutshell")

    ../doc/tmap-nutshell.html

  • tm_facets 57

    Examples

    data(World, Europe, NLD_muni, NLD_prov, land, metro)

    current.mode

  • 58 tm_facets

    tm_facets(by="name", free.coords=TRUE, drop.units=TRUE)

    tm_shape(land) +tm_raster("black") +tm_facets(by="cover_cls")

    ## End(Not run)

    # Facets defined by groupings defined by two variables## Not run:World$HPI3

  • tm_fill 59

    tm_fill Draw polygons

    Description

    Creates a tmap-element that draws the polygons. tm_fill fills the polygons. Either a fixed color isused, or a color palette is mapped to a data variable. tm_borders draws the borders of the polygons.tm_polygons fills the polygons and draws the polygon borders.

    Usage

    tm_fill(col = NA, alpha = NA, palette = NULL, convert2density = FALSE,area = NULL, n = 5, style = ifelse(is.null(breaks), "pretty", "fixed"),breaks = NULL, labels = NULL, auto.palette.mapping = TRUE,contrast = NA, max.categories = 12, colorNA = NA, textNA = "Missing",showNA = NA, thres.poly = 0, title = NA, legend.show = TRUE,legend.format = list(), legend.is.portrait = TRUE, legend.hist = FALSE,legend.hist.title = NA, legend.z = NA, legend.hist.z = NA, id = NA,...)

    tm_borders(col = NA, lwd = 1, lty = "solid", alpha = NA)

    tm_polygons(col = NA, alpha = NA, border.col = NA, border.alpha = NA,...)

    Arguments

    col For tm_fill, it is one of

    • a single color value• the name of a data variable that is contained in shp. Either the data vari-

    able contains color values, or values (numeric or categorical) that will bedepicted by a color palette (see palette. In the latter case, a choropleth isdrawn. #’

    • "MAP_COLORING". In this case polygons will be colored such that adja-cent polygons do not get the same color. See the underlying functionmap_coloring for details.

    For tm_borders, it is a single color value that specifies the border line color. Ifmultiple values are specified, small multiples are drawn (see details).

    alpha transparency number between 0 (totally transparent) and 1 (not transparent). Bydefault, the alpha value of the col is used (normally 1).

    palette a palette name or a vector of colors. See RColorBrewer::display.brewer.all()for the named palette. Use a "-" as prefix to reverse the palette. The defaultpalette is taken from tm_layout’s argument aes.palette.

  • 60 tm_fill

    convert2density

    boolean that determines whether col is converted to a density variable. Shouldbe TRUE when col consists of absolute numbers. The area size is either approx-imated from the shape object, or given by the argument area.

    area Name of the data variable that contains the area sizes in squared kilometer.

    n preferred number of classes (in case col is a numeric variable).

    style method to process the color scale when col is a numeric variable. Discrete op-tions are "cat", "fixed", "sd", "equal", "pretty", "quantile", "kmeans","hclust", "bclust", "fisher", and "jenks". A numeric variable is processedas a categorial variable when using "cat", i.e. each unique value will corre-spond to a distinct category. For the other discrete options, see the details inclassIntervals. Continuous options are "cont" and "order". The former mapsthe values of col to a smooth gradient, whereas the latter maps the order of val-ues of col to a smooth gradient. They are the continuous variants of respectivelythe discrete methods "equal" and quantile".

    breaks in case style=="fixed", breaks should be specified.

    labels labels of the classes.auto.palette.mapping

    When diverging colour palettes are used (i.e. "RdBu") this method automaticallymaps colors to values such that the middle colors (mostly white or yellow) areassigned to values of 0, and the two sides of the color palette are assigned tonegative respectively positive values. When categorical color palettes are used,this method stretches the palette is there are more levels than colors.

    contrast vector of two numbers that determine the range that is used for sequential anddiverging palettes (applicable when auto.palette.mapping=TRUE). Both num-bers should be between 0 and 1. The first number determines where the palettebegins, and the second number where it ends. For sequential palettes, 0 meansthe brightest color, and 1 the darkest color. For diverging palettes, 0 means themiddle color, and 1 both extremes. If only one number is provided, this numberis interpreted as the endpoint (with 0 taken as the start).

    max.categories in case col is the name of a categorical variable, this value determines howmany categories (levels) it can have maximally. If the number of levels is higherthan max.categories and auto.palette.mapping is FALSE, then levels arecombined.

    colorNA color used for missing values. Use NULL for transparency.

    textNA text used for missing values.

    showNA logical that determines whether missing values are named in the legend. Bydefault (NA), this depends on the presence of missing values.

    thres.poly number that specifies the threshold at which polygons are taken into account.The number itself corresponds to the proportion of the area sizes of the polygonsto the total polygon size. By default, all polygons are drawn. To ignore polygonsthat are not visible in a normal plot, a value like 1e-05 is recommended.

    title title of the legend element

    legend.show logical that determines whether the legend is shown

  • tm_fill 61

    legend.format list of formatting options for the legend numbers. Only applicable if labels isundefined. Parameters are:

    scientific Should the labels be formatted scientically? If so, square brackets areused, and the format of the numbers is "g". Otherwise, format="f", andtext.separator, text.less.than, and text.or.more are used. Also,the numbers are automatically rounded to millions or billions if applicable.

    format By default, "f", i.e. the standard notation xxx.xxx, is used. If scientific=TRUEthen "g", which means that numbers are formatted scientically, i.e. n.dddE+nnif needed to save space.

    digits Number of digits after the decimal point if format="f", and the numberof significant digits otherwise.

    text.separator Character string to use to separate numbers in the legend (de-fault: "to").

    text.less.than Character string to use to translate "Less than" (which is the de-fault).

    text.or.more Character string to use to translate "or more" (which is the de-fault).

    ... Other arguments passed on to formatClegend.is.portrait

    logical that determines whether the legend is in portrait mode (TRUE) or land-scape (FALSE)

    legend.hist logical that determines whether a histogram is shownlegend.hist.title

    title for the histogram. By default, one title is used for both the histogram andthe normal legend.

    legend.z index value that determines the position of the legend element with respect toother legend elements. The legend elements are stacked according to their zvalues. The legend element with the lowest z value is placed on top.

    legend.hist.z index value that determines the position of the histogram legend element

    id name of the data variable that specifies the indices of the polygons. Only usedfor "view" mode (see tmap_mode).

    ... for tm_polygons, these arguments passed to either tm_fill or tm_borders.For tm_fill, these arguments are passed on to map_coloring.

    lwd border line width (see par)

    lty border line type (see par)

    border.col border line color

    border.alpha transparency number between 0 (totally transparent) and 1 (not transparent). Bydefault, the alpha value of the col is used (normally 1).

    Details

    Small multiples can be drawn in two ways: either by specifying the by argument in tm_facets,or by defining multiple variables in the aesthetic arguments. The aesthetic argument of tm_fill(and tm_polygons) is col. In the latter case, the arguments, except for thres.poly, and the ones

  • 62 tm_fill

    starting with legend., can be specified for small multiples as follows. If the argument normallyonly takes a single value, such as n, then a vector of those values can be specified, one for eachsmall multiple. If the argument normally can take a vector, such as palette, then a list of thosevectors (or values) can be specified, one for each small multiple.

    Value

    tmap-element

    See Also

    vignette("tmap-nutshell")

    Examples

    data(World, Europe, NLD_muni, NLD_prov)

    # Constant filltm_shape(World) + tm_fill("darkolivegreen3") + tm_format_World(title="A green World")

    # Borders onlytm_shape(Europe) + tm_borders()

    # Data variable containing colours valuesEurope$isNLD

  • tm_grid 63

    tm_shape(World) +tm_polygons("economy", title="Economy", id="name") +tm_text("iso_a3", size="AREA", scale=1.5) +

    tm_format_World()

    # Map coloring algorithm## Not run:tm_shape(NLD_prov) +

    tm_fill("name", legend.show = FALSE) +tm_shape(NLD_muni) +

    tm_polygons("MAP_COLORS", palette="Greys", alpha = .25) +tm_shape(NLD_prov) +

    tm_borders(lwd=2) +tm_text("name", shadow=TRUE) +

    tm_format_NLD(title="Dutch