-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
64 lines (43 loc) · 1.76 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
---
output:
github_document
---
# ggbrick <img src='dev/images/ggbrick1.png' align="right" height="240" />
Create a 'waffle' style chart with the aesthetic of a brick wall.
Usage is similar to `geom_col` where you supply counts as the height of the bar. Each whole brick represents 1 unit. Two half bricks equal one whole brick. Where the count exceeds the number of brick layers, the number of bricks is scaled to retain the brick wall aesthetic.
## Installation
Install from Git
```{r, eval = FALSE}
devtools::install_github("doehm/ggbrick")
```
Simple example
```{r, eval = FALSE}
library(ggplot2)
library(ggbrick)
d10 <- c("#788FCE", "#BD8184", "#E6956F", "#F2CC8F", "#A6BA96", "#C5E8E3",
"#F4F1DE", "#CDC3D4", "#A88AD2", "#60627C")
mpg |>
count(class, drv) |>
ggplot() +
geom_brick(aes(class, n, fill = drv)) +
scale_fill_manual(values = d10)
```
<img src='dev/images/pic0.png'>
The fill can be randomised to create a different look with `type = 'random'` or `type = 'soft_random'`.
<img src='dev/images/pic2.png'>
In this case each brick represents a car (a row) in `mpg`. When the number of bricks gets too large, the number of brick layers will be capped and the number of bricks will be scaled down. The proportions of the fill aesthetic will be held consistent. This can be adjusted with the `brick_layers` parameter.
```{r, eval = FALSE}
mpg |>
count(class, trans) |>
mutate(n = 5*n) |>
ggplot() +
geom_brick(aes(class, n, fill = trans)) +
scale_fill_manual(values = d10)
```
<img src='dev/images/pic1.png'>
You can also adjust the number of bricks per layer with the `bricks_per_layer` parameter.
```{r, eval = FALSE}
ggplot() +
geom_brick(aes(x = 1, y = 96), fill = "firebrick", bricks_per_layer = 8)
```
<img src='dev/images/pic3.png'>