grid_bars: Calculate polygons for a binned-categorical bar plot

Description Usage Arguments Value Examples

Description

Take gridded data with a categorical variable and calculate polygons for a binned categorical bar plot

Usage

1
grid_bars(x, FUN = sum, yscale = 1)

Arguments

x

data.frame with first 2 columns as x/y axis points for gridded data, a 3rd categorical column, and a 4th column of values to aggregate

FUN

Character string/vector of in-built R aggregation function(s) or a callback function compatible with aggregate()'s FUN argument, to aggregate data input as 'z'. E.g. "min", "max", "mean", "median". For frequency counts use "length" (which will also work if no input for 'z' is provided). A string vector can be passed to apply multiple functions to apply seperately to vector 'z' or individually to the columns of a matrix/data.frame.

yscale

Numeric, Multiplier for bar heights

Value

A data.frame of polygon vertex coordinates and corresponding fields

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
d = faithful
d$cat = sample(c('A','A','A','A','B','B','C'), nrow(d), rep=TRUE)
d$size = round(10 * rlnorm(nrow(d)))

gridded = grid_points(d[,1:2], z=d[,c('size')], grp=d[,c('cat')], nx = 20, FUN = mean)

polys = grid_bars(gridded)

require(ggplot2)
ggplot(polys) + geom_polygon(aes(x, y, group = id, fill = grp))

geotheory/gridPoints documentation built on May 17, 2019, 1:15 a.m.