grid_bars | R Documentation |
Take gridded data with a categorical variable and calculate polygons for a binned categorical bar plot
grid_bars(x, FUN = sum, yscale = 1)
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 |
A data.frame of polygon vertex coordinates and corresponding fields
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.