Coder Social home page Coder Social logo

ggbg's Introduction

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

ggbg's People

Contributors

brodieg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dpseidel quanrd

ggbg's Issues

HW in copyrights

We removed him, but there may still be a few chunks of code with sourced directly (see utils.R)

Contribute to ggforce?

There is some neat functionality here, but it seems like this package is pretty experimental and it's not clear if you ever intend to publish to CRAN. Have you considered contributing to ggforce? I discovered your package in the process of opening an issue request for waterfall plots and it looks like you've already done a lot of the work here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.