Skip to content

brodieG/ggbg

Repository files navigation

ggbg - Assorted Ggplot Extensions

Assorted experimental ggplot2 extensions. This package is partly a learning exercise for myself, so not all contents will be useful to others.

position_waterfall

A position adjustment that both stacks and dodges bars to create waterfall charts:

set.seed(1)
p <- ggplot(data.frame(x=1:20, y=rnorm(20)), aes(x=x, y=y, fill=y > 0))
p + geom_col()
p + geom_col(position='waterfall')

plot of chunk waterfallplot of chunk waterfall

It is primarily intended for geom_col, but can be used with arbitrary geoms:

p + geom_point()
p + geom_point(position=position_waterfall(vjust=1))

plot of chunk geomsplot of chunk geoms

If you use arbitrary geoms you may need to adjust position with vjust as we do here as otherwise the graphical elements are centered between the end of the previous cumulative value and the beginning of the next. Please see ?position_watefall for details.

It is can also be used with stats:

dat.norm <- data.frame(x=rnorm(1000))
ggplot(dat.norm, aes(x=x)) + stat_bin()
ggplot(dat.norm, aes(x=x)) + stat_bin(position='waterfall')

plot of chunk statsplot of chunk stats

For more examples try example(position_waterfall, package='ggbg').

geom_car

Plot cars! This geom was implemented on a lark as an answer to an SO Question.

ggplot(
  geom.car.data,  # ggbg data set
  aes(x=x, y=y, length=length, width=width, fill=label)
) +
geom_hline(yintercept=seq(5, 35, by=10), color="white", size=2, linetype=2) +
geom_car() +
coord_equal() +
theme(panel.background = element_rect(fill="#555555"),
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank())

plot of chunk geom-car

Installation

This package is currently github-only. You can get it with devtools::install_github('brodieg/ggbg') or:

f.dl <- tempfile()
f.uz <- tempfile()
github.url <- 'https://github.com/brodieG/ggbg/archive/master.zip'
download.file(github.url, f.dl)
unzip(f.dl, exdir=f.uz)
install.packages(file.path(f.uz, 'ggbg-master'), repos=NULL, type='source')
unlink(c(f.dl, f.uz))

Related Packages

Acknowledgments

About

Miscellaneous Ggplot2 Extensions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages