plot_GCAM: Primary GCAM mapping function. Can handle categorical or...

Description Usage Arguments Details Examples

View source: R/Map_Functions.R

Description

This function produces a map visualization of a data set containing GCAM output data. The required argument is a data frame of GCAM results by region. The function getQuery produces suitable data frames.

Usage

1
2
3
4
5
plot_GCAM(mapdata, col = NULL, proj = robin, proj_type = NULL,
  extent = EXTENT_WORLD, title = "", legend = F, gcam_df = NULL,
  gcam_key = "id", mapdata_key = "region_id", zoom = 0,
  graticules = "bottom", agr_type = "constant",
  background_color = MAP_BACKGROUND, padding = all(extent == EXTENT_WORLD))

Arguments

mapdata

The data frame containing both geometric data (simple features collection and id) and regional metadata. This is the only mandatory variable. If used alone, will produce the default map.

col

If plotting categorical/continuous data, the name of the column to plot. Will automatically determine type of style of plot based on type of data (numeric or character).

proj

Map projection to use in the display map. This should be a proj4 string, except for a few special cases. There are also symbols defined for some frequently used projections (e.g. robin or na_aea).

proj_type

Either esri, epsg, or sr-org as string. These correspond to available reference types hosted by http://spatialreference.org/.

extent

Numeric bounds [xmin, xmax, ymin, ymax] to zoom display to.

title

Text to be displayed as the plot title.

legend

Boolean flag: True = display map legend; False = do not display legend.

gcam_df

A data frame generated from the rgcam function getQuery. Also accepts other data frames that contain data that can be linked to the map geometry data using a unique identifier.

gcam_key

The field name containing a join identifier in the gcam_df data frame.

mapdata_key

The field name containing a join identifier in the mapdata.

zoom

A distance to buffer the bounding box extent by for on-the-fly adjustments needed when fitting area to maps.

graticules

Where to position any graticules. One of 'top', 'bottom', or ” (empty string). Note that 'bottom' places them under the map background and will not be visible without a setting the background_color parameter to NA or transparent.

agr_type

Aggregate-geometry-relationship type. Either 'constant' (default), 'aggregate', or 'identity' classified as follows: [constant] a variable that has a constant value at every location over a spatial extent; examples: soil type, climate zone, land use. [aggregate] values are summary values (aggregates) over the geometry, e.g. population density, dominant land use. [identity] values identify the geometry: they refer to (the whole of) this and only this geometry. See the sf vignette for further explanation.

background_color

Color for the areas with no regions (the oceans)

padding

Boolean flag: Add space between map edge and plot edge?

Details

We don't try to take the color mapping, legend title, etc. as arguments to this function. The ggplot2 way of specifying this information is way more flexible. To customize your color mapping, use one of

If you choose to display a legend for the color mapping, you will have to give it a title using the title argument to any of the above gradient functions. You have to do this even if you want a legend with no title at all. Use an empty string in that case.

For specifying the projection you can use any Proj4 string. For convenience, this package defines the following proj4 strings:

The extent argument gives the bounding box of the area to be plotted. Its format is c(lon.min, lon.max, lat.min, lat.max). For convenience we have defined the following frequently used map extents:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 

## Plot a map of GCAM regions; color it with the default theme palette.
plot_GCAM(map.rgn32.simple, col = 'region_name', proj = eck3) +
    ggplot2::scale_fill_manual(values = gcam32_colors, na.value=gray(0.75))

## Plot refined liquids production by region for the year 2050
prj <- loadProject(system.file('sample-gcam-data',
                               'gcam-longform-sample.dat',
                               package='gcammaptools'))
ref_liquids <- rgcam::getQuery(prj, 'Refined liquids production by region', 'Reference')
ref_liquids <- add_region_ID(ref_liquids, lookupfile=rgn32, drops=rgn32)
ref_liquids <- dplyr::filter(ref_liquids, year==2050)
plot_GCAM(map.rgn32.simple, col='value', proj=robin, title="Robinson World",
          legend=T, gcam_df=co2, gcam_key='id', mapdata_key="region_id") +
   ggplot2::scale_fill_gradientn(colors = c("white", "red"),
                                 na.value = gray(0.75),
                                 name="CO2 Emissions (MTC)")

## End(Not run)

JGCRI/gcammaptools documentation built on May 4, 2018, 8 a.m.