riding_binplot: Canadian federal ridings tile plot function

Description Usage Arguments Examples

Description

A function that returns a data frame with map data, for use in ggplot.

Usage

1
2
3
4
riding_binplot(riding_data, riding_col = riding_code, value_col,
  continuous = TRUE, arrange = FALSE, riding_border_col = "white",
  year = 2015, riding_border_size = 1, provincial = FALSE,
  shape = "square", province, legend_name = "default")

Arguments

riding_data

A dataframe with a continuous or categorical riding-level characteristic and a riding code variable.

riding_col

An unquoted character expression specifying the riding code variable from the dataframe provided in riding_data.

value_col

An unquoted character expression specifying the column or categorical riding level characteristic you would like to visualize.

continuous

logical. Specify as FALSE if the variable is categorical (e.g. for winning party) and TRUE if the variable is continuous.

arrange

logical. Specify as TRUE if variable should be ranked according to value within provinces and FALSE to plot values according to riding coordinates. Because the binned ridings are only a rough approximation of their actual location, arrange = TRUE is often preferable.

riding_border_col

To ensure the appearance of stand alone tiles, set 'riding_border_col' to be the same as the background colour of the plot. Default is "white".

year

Election year. Options are 1997, 2000, 2004, 2006, 2008, 2011 and 2015. This will change the number of tiles to correspond to the number of ridings in the election of the specified year. Default is 2015

riding_border_size

Change the size of tiles. Larger values make smaller tiles. Default is 1.

provincial

logical. Specify as FALSE for provincial (not federal) ridings of a single province. If provincial = TRUE, specify a 2-letter provincial abbreviation for the province in the province argument. Default is FALSE (i.e. the default is to provide federal electoral boundaries). (Note: this argument is still in development, only Quebec provincial boundaries are available at the moment.)

shape

Unquoted character expression specifying shape of tiles. Options are square and hexagon, default is square.

province

An unquoted character expression specifying the 2-letter provincial abbreviation of the province for which provincial electoral boundaries are desired. (Note: this argument is still in development, only Quebec provincial boundaries are available at the moment.)

legend_name

Quoted chacter expression specifying the title of the legend. The variable name will be used as a default if no value is supplied.

Examples

1
2
3
4
election_2015 <- federal_election_results[federal_election_results$election_year == 2015, ]

riding_binplot(riding_data = election_2015, riding_col = riding_code,
value_col = party, continuous = FALSE, arrange = TRUE)

mapcan documentation built on May 9, 2019, 5:03 p.m.