Skip to content

Commit 4b05a3b

Browse files
committed
Update blog post
1 parent a490015 commit 4b05a3b

File tree

1 file changed

+76
-62
lines changed

1 file changed

+76
-62
lines changed

vignettes/releases/ggplot2-2.2.0.Rmd

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,30 @@ knitr::opts_chunk$set(
2121
fig.retina = NULL
2222
)
2323
```
24+
<meta charset="utf-8">
2425

25-
I'm planning to release ggplot2 2.2.0 in early November. In preparation, I'd like to announce that a release candidate is now available: version 2.1.0.9001. Please try it out, and file an [issue on GitHub](https://github.com/tidyverse/ggplot2/issues) if you discover any problems. I hope we can find and fix any major issues before the official release.
26+
I'm very pleased to announce ggplot2 2.2.0. It includes four major new features:
2627

27-
Install the pre-release version with:
28+
* Subtitles and captions.
29+
* A large rewrite of the facetting system.
30+
* Improved theme options.
31+
* Better stacking.
2832

29-
```{r, eval = FALSE}
30-
# install.packages("devtools")
31-
devtools::install_github("tidyverse/ggplot2")
32-
```
33+
It also includes as numerous bug fixes and minor improvements, as described in the [release notes](http://github.com/hadley/ggplot2/releases/tag/v2.2.0).
34+
35+
The majority of this work was carried out by [Thomas Pederson](https://github.com/thomasp85), who I was lucky to have as my "ggplot2 intern" this summer. Make sure to check out his other visualisation packages: [ggraph](https://github.com/thomasp85/ggraph), [ggforce](https://github.com/thomasp85/ggforce), and [tweenr](https://github.com/thomasp85/tweenr).
3336

34-
If you discover a major bug that breaks your plots, please [file a minimal reprex](https://github.com/tidyverse/ggplot2/issues), and then roll back to the released version with:
37+
Install ggplot2 with:
3538

3639
```{r, eval = FALSE}
3740
install.packages("ggplot2")
3841
```
3942

40-
ggplot2 2.2.0 will be a relatively major release including:
41-
42-
* Subtitles and captions.
43-
* A large rewrite of the facetting system.
44-
* Improved theme options.
45-
* Better stacking
46-
* [Numerous bug fixes and minor improvements][news.md].
47-
48-
The majority of this work was carried out by [Thomas Pederson](https://github.com/thomasp85), who I was lucky to have as my "ggplot2 intern" this summer. Make sure to check out other visualisation packages: [ggraph](https://github.com/thomasp85/ggraph), [ggforce](https://github.com/thomasp85/ggforce), and [tweenr](https://github.com/thomasp85/tweenr).
49-
5043
## Subtitles and captions
5144

52-
Thanks to [Bob Rudis](https://rud.is), you can now add subtitles and captions:
45+
Thanks to [Bob Rudis](https://rud.is), you can now add subtitles and captions to your plots:
5346

54-
```{r}
47+
```{r subtitle}
5548
ggplot(mpg, aes(displ, hwy)) +
5649
geom_point(aes(color = class)) +
5750
geom_smooth(se = FALSE, method = "loess") +
@@ -64,44 +57,43 @@ ggplot(mpg, aes(displ, hwy)) +
6457

6558
These are controlled by the theme settings `plot.subtitle` and `plot.caption`.
6659

67-
The plot title is now aligned to the left by default. To return to the previous centering, use `theme(plot.title = element_text(hjust = 0.5))`.
60+
The plot title is now aligned to the left by default. To return to the previous centered alignment, use `theme(plot.title = element_text(hjust = 0.5))`.
6861

6962
## Facets
7063

71-
The facet and layout implementation has been moved to ggproto and received a large rewrite and refactoring. This will allow others to create their own facetting systems, as descrbied in the *Extending ggplot2* vignette. Along with the rewrite a number of features and improvements has been added, most notably:
72-
73-
* Functions in facetting formulas, thanks to
64+
The facet and layout implementation has been moved to ggproto and received a large rewrite and refactoring. This will allow others to create their own facetting systems, as descrbied in the `vignette("extending-ggplot2")`. Along with the rewrite a number of features and improvements has been added, most notably:
65+
66+
* ou can now use functions in facetting formulas, thanks to
7467
[Dan Ruderman](https://github.com/DanRuderman).
75-
76-
```{r}
68+
69+
```{r facet-1}
7770
ggplot(diamonds, aes(carat, price)) +
7871
geom_hex(bins = 20) +
7972
facet_wrap(~cut_number(depth, 6))
8073
```
8174
82-
* Axes were dropped when the panels in `facet_wrap()` did not completely
83-
fill the rectangle. Now, an axis is drawn underneath the hanging panels:
75+
* Axes are now drawn under the panels in `facet_wrap()` when the
76+
rentangle is not completely filled.
8477
85-
```{r}
78+
```{r facet-2}
8679
ggplot(mpg, aes(displ, hwy)) +
8780
geom_point() +
8881
facet_wrap(~class)
8982
```
9083
91-
* It is now possible to set the position of the axes through the `position`
92-
argument in the scale constructor:
93-
94-
```{r}
84+
* You can set the position of the axes with the `position` argument.
85+
86+
```{r facet-3}
9587
ggplot(mpg, aes(displ, hwy)) +
9688
geom_point() +
9789
scale_x_continuous(position = "top") +
9890
scale_y_continuous(position = "right")
9991
```
10092
101-
* You can display a secondary axis that is a one-to-one transformation of the
102-
primary axis with the `sec.axis` argument:
103-
104-
```{r}
93+
* You can display a secondary axis that is a one-to-one transformation of
94+
the primary axis with `sec.axis`.
95+
96+
```{r facet-4}
10597
ggplot(mpg, aes(displ, hwy)) +
10698
geom_point() +
10799
scale_y_continuous(
@@ -110,10 +102,10 @@ The facet and layout implementation has been moved to ggproto and received a lar
110102
)
111103
```
112104
113-
* Strips can be placed on any side, and the placement with respect to axes
114-
can be controlled with the `strip.placement` theme option.
115-
116-
```{r}
105+
* Strips can be placed on any side, and the placement with respect to axes
106+
can be controlled with the `strip.placement` theme option.
107+
108+
```{r facet-5}
117109
ggplot(mpg, aes(displ, hwy)) +
118110
geom_point() +
119111
facet_wrap(~ drv, strip.position = "bottom") +
@@ -127,12 +119,15 @@ The facet and layout implementation has been moved to ggproto and received a lar
127119
128120
## Theming
129121
122+
* The `theme()` function now has named arguments so autocomplete
123+
and documentation suggestions are vastly improved.
124+
130125
* Blank elements can now be overridden again so you get the expected
131126
behavior when setting e.g. `axis.line.x`.
132127
133128
* `element_line()` gets an `arrow` argument that lets you put arrows on axes.
134129
135-
```{r}
130+
```{r theme-1}
136131
arrow <- arrow(length = unit(0.4, "cm"), type = "closed")
137132
138133
ggplot(mpg, aes(displ, hwy)) +
@@ -144,42 +139,40 @@ The facet and layout implementation has been moved to ggproto and received a lar
144139
```
145140
146141
* Control of legend styling has been improved. The whole legend area can be
147-
aligned according to the plot area and a box can be drawn around all legends:
142+
aligned with the plot area and a box can be drawn around all legends:
148143
149-
```{r}
144+
```{r theme-2}
150145
ggplot(mpg, aes(displ, hwy, shape = drv, colour = fl)) +
151146
geom_point() +
152147
theme(
153148
legend.justification = "top",
149+
legend.box = "horizontal",
154150
legend.box.margin = margin(3, 3, 3, 3, "mm"),
151+
legend.margin = margin(),
155152
legend.box.background = element_rect(colour = "grey50")
156153
)
157154
```
158155
159156
* `panel.margin` and `legend.margin` have been renamed to `panel.spacing`
160-
and `legend.spacing` respectively as this better indicates their roles.
161-
A new `legend.margin` has been actually controls the margin around each
162-
legend.
157+
and `legend.spacing` respectively, as this better indicates their roles.
158+
A new `legend.margin` actually controls the margin around each legend.
163159
164-
* When computing the height of titles ggplot2, now inclues the height of the
165-
descenders (i.e. the bits `g` and `y` that hang underneath). This makes
166-
improves the margins around titles, particularly the y axis label. I have
167-
also very slightly increased the inner margins of axis titles, and removed
168-
the outer margins.
160+
* When computing the height of titles, ggplot2 now inclues the height of the
161+
descenders (i.e. the bits `g` and `y` that hang underneath). This improves
162+
the margins around titles, particularly the y axis label. I have also very
163+
slightly increased the inner margins of axis titles, and removed the outer
164+
margins.
169165
170166
* The default themes has been tweaked by
171167
[Jean-Olivier Irisson](http://www.obs-vlfr.fr/~irisson/) making them better
172168
match `theme_grey()`.
173169
174-
* Lastly, the `theme()` function now has named arguments so autocomplete
175-
and documentation suggestions are vastly improved.
176-
177170
## Stacking bars
178171
179172
`position_stack()` and `position_fill()` now stack values in the reverse
180173
order of the grouping, which makes the default stack order match the legend.
181174
182-
```{r}
175+
```{r stack-1}
183176
avg_price <- diamonds %>%
184177
group_by(cut, color) %>%
185178
summarise(price = mean(price)) %>%
@@ -193,22 +186,43 @@ ggplot(avg_price) +
193186
(Note also the new `geom_col()` which is short-hand for
194187
`geom_bar(stat = "identity")`, contributed by Bob Rudis.)
195188

189+
If you want to stack in the opposite order, try
190+
[`forcats::fct_rev()`](http://forcats.tidyverse.org/reference/fct_rev.html):
191+
192+
```{r stack-2}
193+
ggplot(avg_price) +
194+
geom_col(aes(x = cut, y = price, fill = fct_rev(color)))
195+
```
196+
196197
Additionally, you can now stack negative values:
197198

198-
```{r}
199+
```{r stack-3}
199200
ggplot(avg_price) +
200201
geom_col(aes(x = cut, y = price_rel, fill = color))
201202
```
202203

203204
The overall ordering cannot necessarily be matched in the presence of
204205
negative values, but the ordering on either side of the x-axis will match.
205206

206-
If you want to stack in the opposite order, try
207-
[`forcats::fct_rev()`](http://forcats.tidyverse.org/reference/fct_rev.html):
207+
Labels can also be stacked, but the default position is suboptimal:
208208

209-
```{r}
210-
ggplot(avg_price) +
211-
geom_col(aes(x = cut, y = price, fill = fct_rev(color)))
209+
```{r stack-4}
210+
series <- data.frame(
211+
time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
212+
type = rep(c('a', 'b', 'c', 'd'), 4),
213+
value = rpois(16, 10)
214+
)
215+
216+
ggplot(series, aes(time, value, group = type)) +
217+
geom_area(aes(fill = type)) +
218+
geom_text(aes(label = type), position = "stack")
219+
```
220+
221+
You can improve the position with the `vjust` parameter. A `vjust` of 0.5 will center the labels inside the corresponding area:
222+
223+
```{r stack-5}
224+
ggplot(series, aes(time, value, group = type)) +
225+
geom_area(aes(fill = type)) +
226+
geom_text(aes(label = type), position = position_stack(vjust = 0.5))
212227
```
213228

214-
[news.md]: https://github.com/tidyverse/ggplot2/blob/master/NEWS.md

0 commit comments

Comments
 (0)