项目作者: brodieG

项目描述 :
Miscellaneous Ggplot2 Extensions
高级语言: R
项目地址: git://github.com/brodieG/ggbg.git
创建时间: 2018-04-08T18:20:26Z
项目社区:https://github.com/brodieG/ggbg

开源协议:

下载


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:

  1. set.seed(1)
  2. p <- ggplot(data.frame(x=1:20, y=rnorm(20)), aes(x=x, y=y, fill=y > 0))
  3. p + geom_col()
  4. 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:

  1. p + geom_point()
  2. 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:

  1. dat.norm <- data.frame(x=rnorm(1000))
  2. ggplot(dat.norm, aes(x=x)) + stat_bin()
  3. 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
.

  1. ggplot(
  2. geom.car.data, # ggbg data set
  3. aes(x=x, y=y, length=length, width=width, fill=label)
  4. ) +
  5. geom_hline(yintercept=seq(5, 35, by=10), color="white", size=2, linetype=2) +
  6. geom_car() +
  7. coord_equal() +
  8. theme(panel.background = element_rect(fill="#555555"),
  9. panel.grid.major = element_blank(),
  10. 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:

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

Acknowledgments