Assorted experimental ggplot2
extensions. This package is partly a learning
exercise for myself, so not all contents will be useful to others.
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')
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))
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')
For more examples try example(position_waterfall, package='ggbg')
.
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())
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))
- R Core for developing and maintaining such a wonderful language.
- CRAN maintainers, for patiently shepherding packages onto CRAN and maintaining the repository, and Uwe Ligges in particular for maintaining Winbuilder.
- Hadley Wickham for
ggplot2
, and in particular for making it so easily extensible. - Jim Hester because covr rocks.
- Dirk Eddelbuettel and Carl Boettiger for the rocker project, and Gábor Csárdi and the R-consortium for Rhub, without which testing bugs on R-devel and other platforms would be a nightmare.
- Hadley Wickham for devtools and with Peter Danenberg for roxygen2.
- Yihui Xie for knitr and J.J. Allaire etal for rmarkdown, and by extension John MacFarlane for pandoc.
- All open source developers out there that make their work freely available for others to use.
- Github, Travis-CI, Codecov, Vagrant, Docker, Ubuntu, Brew for providing infrastructure that greatly simplifies open source development.
- Free Software Foundation for developing the GPL license and promotion of the free software movement.