xtmap: Plot country-level maps

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Function to plot country-level maps. Requires the countrycode, ggplot2, mapproj and maps packages.

Usage

1
2
3
4
5
  xtmap(data, variable, t = NULL, continents = NULL,
    regions = NULL, name = "", title = NULL,
    quantize = FALSE, quantize.t = FALSE, iso3n = NULL,
    simplify = NULL, text.size = 12, ncol = NULL,
    nrow = NULL, ...)

Arguments

data

a data frame.

variable

a variable name.

t

the time period to plot from, as specified in the xtdata attribute of the data. If the data carries an xtdata attribute but t is left unspecified, the maximal value of the time period is used. See 'Details'.

ncol

if the plot is faceted by time periods, the number of facet columns

nrow

if the plot is faceted by time periods, the number of facet rows

continents

a vector of continent names to subset the map to.

regions

a vector of region names to subset the map to.

name

a name to give to the color scale

title

a title to give to the map

quantize

how many quantiles to cut the variable into. Defaults to FALSE, which leaves variable unaffected.

quantize.t

how many time periods to cut the time variable into. Defaults to FALSE, which produces one map per time period. See 'Details'.

text.size

the size for text elements.

iso3n

the ISO-3N variable name, if you are using the function on cross-sectional data (which will return a warning), or if you are overriding the xtdata attribute of the data frame (which also returns a warning).

simplify

the threshold of points under which to remove a geographic subregion. Set to something like 30 to remove islands and overseas areas. More of a bug than a feature. Defaults to NULL, which leaves the map intact.

...

other arguments passed to map_data or map.

Details

The function is intended as a helper to map country-year data. It falls back to mapping the data as a cross-section if the data carries no xtdata attribute or if t is left unspecified, in which case it will map the values of variable for the most recent time period (usually years).

When the data carries an xtdata attribute and t is specified, the function returns facet maps of the data, by time period. Use ncol and nrow to arrange the disposition of the maps. If quantize.t is specified, the time period is cut to quantiles and the mean value of variable are plotted, in order to plot things like average values of a variable over several decades.

Value

a ggplot2 object

Author(s)

Francois Briatte f.briatte@ed.ac.uk

See Also

map_data, map_data, map

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Load QOG demo datasets.
data(qog.demo)
# Fertility rates in Africa, most recent year.
xtmap(qog.ts.demo, "wdi_fr", continent = "Africa")
# Fertility rates in Africa, 1995.
xtmap(qog.ts.demo, "wdi_fr", 1995, continent = "Africa")
# Political regimes in Asia, excluding Russia, using cross-sectional data.
xtmap(subset(qog.cs.demo, ccode != 643), "chga_hinst", continent = "Asia",
      iso3n = "ccode") +
  geom_polygon(color = "grey25") +
  scale_fill_brewer("", palette = "Accent")
# Grayscale version.
xtmap(subset(qog.cs.demo, ccode != 643), "chga_hinst", continent = "Asia",
      iso3n = "ccode") +
  geom_polygon(color = "white") +
  scale_fill_grey("")
# Gross domestic product per capita in Asia, 1980-2009.
xtmap(qog.ts.demo, "wdi_gdpc", t = 1980:2009, continent = "Asia",
      quantize = 10, quantize.t = 4, text.size = 16)

briatte/qogdata documentation built on May 13, 2019, 7:43 a.m.