-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
139 lines (109 loc) Β· 3.37 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
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges()
```
# ggeconodist
Create Diminutive Distribution Charts
## Description
'The Economist' has a unique boxplot aesthetic f or
communicating distrribution characteristics. Tools are provided
to create similar charts in 'ggplot2'.
Inspired by: <https://www.economist.com/united-states/2019/06/29/will-transparent-pricing-make-americas-health-care-cheaper>
## What's Inside The Tin
```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```
The following functions are implemented:
## Installation
```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```
## Usage
```{r lib-ex}
library(ggeconodist)
# current version
packageVersion("ggeconodist")
```
### The whole shebang
**YOU WILL NEED** to install [these fonts](https://github.com/economist-components/component-typography) to use the built-in theme. More on how to do that at some point.
```{r mam}
ggplot(mammogram_costs, aes(x = city)) +
geom_econodist(
aes(ymin = tenth, median = median, ymax = ninetieth),
stat = "identity", show.legend = TRUE
) +
scale_y_continuous(expand = c(0,0), position = "right", limits = range(0, 800)) +
coord_flip() +
labs(
x = NULL, y = NULL,
title = "Mammoscams",
subtitle = "United States, prices for a mammogram*\nBy metro area, 2016, $",
caption = "*For three large insurance companies\nSource: Health Care Cost Institute"
) +
theme_econodist() -> gg
grid.newpage()
left_align(gg, c("subtitle", "title", "caption")) %>%
add_econodist_legend(econodist_legend_grob(), below = "subtitle") %>%
grid.draw()
```
```{r mpg}
library(dplyr)
library(patchwork)
library(hrbrthemes)
library(gapminder)
p <- ggplot(mpg, aes(class, hwy)) + theme_ipsum_rc()
(p + geom_boxplot()) +
(p + geom_econodist(width = 0.25)) +
plot_layout(ncol = 1)
(p + geom_boxplot() + coord_flip()) +
(p + geom_econodist(tenth_col = ft_cols$blue, ninetieth_col = ft_cols$red) +
coord_flip()) +
plot_layout(ncol = 1)
(p + geom_boxplot(aes(fill = factor(drv)))) +
(p + geom_econodist(aes(fill = factor(drv)))) +
plot_layout(ncol = 1)
```
```{r gm, fig.width=600/72, fig.height=700/72}
gapminder %>%
filter(year %in% c(1952, 1962, 1972, 1982, 1992, 2002)) %>%
filter(continent != "Oceania") %>%
ggplot(aes(x = factor(year), y = lifeExp, fill = continent)) +
geom_econodist(
median_point_size = 1.2,
tenth_col = "#b07aa1",
ninetieth_col = "#591a4f",
show.legend = FALSE
) +
ggthemes::scale_fill_tableau(name = NULL) +
coord_flip() +
labs(
x = "Year", title = "Life Expectancy", y = NULL,
caption = "Example borrowed from @cmdline_tips"
) +
facet_wrap(~continent, nrow = 4) +
theme_ipsum_rc() -> gmgg
grid.newpage()
gmgg %>%
add_econodist_legend(
econodist_legend_grob(
tenth_col = "#b07aa1",
ninetieth_col = "#591a4f",
),
below = "axis-b-1-4",
just = "right"
) %>%
grid.draw()
```
## ggeconodist Metrics
```{r cloc, echo = FALSE}
cloc::cloc_pkg_md()
```
## Code of Conduct
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.