wmapfort: Map Plotting Utility for Quick, Already-Fortified Polygons

Description Usage Arguments Value Examples

Description

Simplified plotting utilitity for spatial dataframes based on a chloropleth that has already been transformed into a ggplot fortified object. This decreases loading time for things like shiny apps.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
wmapfort(chloropleth_map, geog_id, variable, outline_map = NULL,
  data = NULL, chlor_lcol = NA, chlor_lsize = 0, histogram = FALSE,
  hist_color = NULL, dist_stats = NULL, mean_color = "red",
  quantile_color = "black", return_map_object_only = FALSE,
  destination_folder = NULL, color_ramp = wpal("easter_to_earth"),
  outline_size = 0.1, outline_color = "white", override_scale = NULL,
  color_value_breaks = NULL, diverging_centerpoint = NULL,
  map_title = " ", map_subtitle = NULL, title_justification = "center",
  additional_variable_name_string = NULL, title_font_size = NULL,
  title_font_face = "plain", fontfamily = "serif", fontsize = 12,
  series_dimension = NULL, series_sequence = NULL, legend_name = NULL,
  legend_position = "bottom", legend_font_size = NULL,
  legend_font_face = "plain", legend_bar_width = 0.4,
  legend_bar_length = 20, legend_breaks = NULL, legend_labels = NULL,
  scramble_colors = FALSE, patch_width = 0.25, patch_height = 0.25,
  label_position = "right", verbose = F)

Arguments

chloropleth_map

A fortified ggplot object with unique geographic ID.

geog_id

string; the column name for the unique geogrpahic ID

variable

string; the column with values you wich to plot

outline_map

Another SpatialPolygons object that you want to use the outlines from. Make sure your outline map and main map have the same projection.

data

A data.table that contains the data you want to map (must contain geog_id, and the variable of interest, if specified. If a series dimension and/or series sequence is defined, those must also exist in this data set)

chlor_lcol

Color of outline of spatialPolygons layer of the main chloropleth SpatialPolygons input. Default is NA.

chlor_lsize

Width of outline of spatialpolygons layer of the main chloropleth SpatialPolygons input. Default is 0.0.

histogram

logical; the plot will contain a histogram of the values

hist_color

If a character string for a color (or colors) are entered (ex:"grey"), the histogram will be that color rather than the color ramp used for the main map.

dist_stats

Vertical lines on the histogram plot showing summary statistics. To show this, provide a vector of numeric values (between 0 and 1) to serve as quantiles, and the options "mean" and "sd" can also be included. example: c("mean","sd",.1,.5,.9). Default=NULL.

mean_color

The color of lines you want to represent mean and standard deviation statistics, only relevant if dist_stats!=NULL. Default="red".

quantile_color

The color of lines you want to represent the median and quantile lines on the histogram, only relevant if dist_stats!=NULL.

return_map_object_only

you can assign the function to a variable, and store the map plot portion of this ggplot object so that you can combine it with other graphics at will. This will never return the histogram.

destination_folder

A string file path to a folder you want a PDF created in that will hold your map(s)

color_ramp

A list of colors that will serve as the colors you "stretch" through based on your data values. This will default to a color scheme described in woodson pallettes called "Easter to Earth" that displays variation well when there are many geographic units. See woodson palletes for more options, or create your own.

outline_size

A numeric value that specifies how large you want your white outlines to be if you have specified an outline you want shown on your map. Default value is .1.

outline_color

What color you want the outline of the additional geography to be (if provided). This can be any color r recognizes suggestions might be "black","yellow", or "white". Default is white.

override_scale

Values that will be used to stretch the color ramp instead of the min/max values present in the entire data set. Should either be structured "c(min,max)", with numeric values, or be "each_dimension", which will create a map series where each individual map in a series will based on the min/max from that subset of data.

color_value_breaks

How you want the colors "stretched" across the range of minimum/maximum values. Default is NULL/ uniform distribution stretched across the color ramp from the minimum and maximum data values provided. Vector must begin with 0 and end with 1.

diverging_centerpoint

Accepts any numeric value between the minimum and maximum of your data set. Sets the center of your color scheme to the value defined. This is meant to be used with diverging color schemes. It will override any previously defined color_value_breaks. Default=NULL.

map_title

A string that serves as the basis for your map title (if no dimensions are specified, the title will be as it is specified. If a dimension is specified, a phrase constructed using the series dimension and what you are mapping will be added to the plot title [ex="year:1990"].

title_justification

Where ("left","center",or "right) you want the title and subtitle. Default is "center".

additional_variable_name_string

This is an additonal string that you want to add to the name of the PDF to describe any other breakdowns you might be using. For example, if you had to map something by year, age, sex, you would first need to subset your data to be one age/sex group before plotting it out by year. If you subset your data in a loop, you could use this string to specify something along the lines of paste0("age_ ",a," _ sex _",s).

title_font_size

How large you want the title font to be. No default; default values based on ggthemes tufte()'s default.

title_font_face

Special properties of the title font. Options include "plain", "bold", "italic". Default is plain.

fontfamily

The name of the font family you want to use for the text on the plot. Default is 'serif'.

fontsize

The base/minimum size of the text on your graphic. Default is NULL.

series_dimension

A string– the name of the column that will serve as the variable you loop through to create a series map. For example, year.

series_sequence

A vector c(x,y,z...) that specifies a subset of the series dimensions you want to map. For example, if you have a data set that contains all years between 1980-2014, you can specify that you only want to plot out every other year by setting series sequence to be seq(1980,2014,2). This function will make sure all of the items you speficy actually exist within your series_dimension.

legend_name

Title above the legend. Default is NULL.

legend_position

Where you want the legend to go. Options are "top","bottom","right","left", and "none". Default is "bottom".

legend_font_size

How large you want the legend font to be. No default; default values based on ggthemes tufte()'s default.

legend_font_face

Special properties of the legend font. Options include "plain", "bold", "italic". Default is plain.

legend_bar_width

How fat you want the color bar that serves as the legend to be. Default value is 0.4.

legend_bar_length

How long you want the color bar that serves as the legend to be. Default value is 20.

legend_breaks

An optional vector of the values you want to label in your legend's color scale.

legend_labels

An optional vector of the character strings you want to use to label your legend's color scale (must be same length as legend_breaks)

scramble_colors

Logical; Scrambles the input color ramp's values. useful for categorical data.

patch_width

width of color swatches in legend when categorical data is used. Default is .25.

patch_height

height of color swatches in legend when categorical data is used. Default is .25.

label_position

Position of category labels in legend when categorical data is used. Default= "right".

verbose

logical; Whether you want print statements from the function scramble_colors=FALSE,

Value

ggplot object or None (plots written to pdf)

Examples

1
see https://rpubs.com/BeccaStubbs/introduction_to_woodson_mapping_suite

RebeccaStubbs/woodson documentation built on May 9, 2019, 9:37 a.m.