-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
145 lines (123 loc) · 5.47 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "##",
fig.path = "man/figures/README-",
error = TRUE
)
library(ggbg)
library(ggplot2)
```
## ggbg - Assorted Ggplot Extensions
[![](https://travis-ci.org/brodieG/ggbg.svg?branch=master)](https://travis-ci.org/brodieG/ggbg)
[![](https://codecov.io/github/brodieG/ggbg/coverage.svg?branch=master)](https://codecov.io/github/brodieG/ggbg?branch=master)
[![](http://www.r-pkg.org/badges/version/ggbg)](https://cran.r-project.org/package=ggbg)
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:
```{r eval=FALSE}
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')
```
```{r waterfall, echo=FALSE, fig.width=5, fig.height=4, out.width='49%'}
set.seed(1)
p <- ggplot(data.frame(x=1:20, y=rnorm(20)), aes(x=x, y=y, fill=y > 0)) +
guides(fill=FALSE)
p + geom_col() + ggtitle('geom_col()')
p + geom_col(position='waterfall') + ggtitle('geom_col(position="waterfall")')
```
It is primarily intended for `geom_col`, but can be used with arbitrary geoms:
```{r eval=FALSE}
p + geom_point()
p + geom_point(position=position_waterfall(vjust=1))
```
```{r geoms, echo=FALSE, fig.width=5, fig.height=4, out.width='49%'}
p + geom_point() + ggtitle('geom_point()')
p + geom_point(position=position_waterfall(vjust=1)) +
ggtitle('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:
```{r eval=FALSE}
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')
```
```{r stats, echo=FALSE, fig.width=5, fig.height=4, out.width='49%'}
dat.norm <- data.frame(x=rnorm(1000))
ggplot(dat.norm, aes(x=x)) + stat_bin(bins=30) + ggtitle('stat_bin()')
ggplot(dat.norm, aes(x=x)) + stat_bin(bins=30, position='waterfall') +
ggtitle('stat_bin(position="waterfall")')
```
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](https://stackoverflow.com/questions/22159087/is-it-possible-to-draw-diagrams-in-r/22207979#22207979).
```{r geom-car, fig.width=7, fig.height=2.5, out.width='99%'}
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())
```
## Installation
This package is currently github-only. You can get it with
`devtools::install_github('brodieg/ggbg')` or:
```{r eval=FALSE}
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
* [ggplot2](https://github.com/tidyverse/ggplot2)
## Acknowledgments
* 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](http://win-builder.r-project.org/).
* [Hadley Wickham](https://github.com/hadley/) for `ggplot2`, and in particular
for making it so easily extensible.
* [Jim Hester](https://github.com/jimhester) because
[covr](https://cran.r-project.org/package=covr) rocks.
* [Dirk Eddelbuettel](https://github.com/eddelbuettel) and [Carl
Boettiger](https://github.com/cboettig) for the
[rocker](https://github.com/rocker-org/rocker) project, and [Gábor
Csárdi](https://github.com/gaborcsardi) and the
[R-consortium](https://www.r-consortium.org/) for
[Rhub](https://github.com/r-hub), without which testing bugs on R-devel and
other platforms would be a nightmare.
* [Hadley Wickham](https://github.com/hadley/) for
[devtools](https://cran.r-project.org/package=devtools) and with [Peter
Danenberg](https://github.com/klutometis) for
[roxygen2](https://cran.r-project.org/package=roxygen2).
* [Yihui Xie](https://github.com/yihui) for
[knitr](https://cran.r-project.org/package=knitr) and [J.J.
Allaire](https://github.com/jjallaire) etal for
[rmarkdown](https://cran.r-project.org/package=rmarkdown), and by extension
John MacFarlane for [pandoc](http://pandoc.org/).
* All open source developers out there that make their work freely available
for others to use.
* [Github](https://github.com/), [Travis-CI](https://travis-ci.org/),
[Codecov](https://codecov.io/), [Vagrant](https://www.vagrantup.com/),
[Docker](https://www.docker.com/), [Ubuntu](https://www.ubuntu.com/),
[Brew](https://brew.sh/) for providing infrastructure that greatly simplifies
open source development.
* [Free Software Foundation](http://fsf.org/) for developing the GPL license and
promotion of the free software movement.