Skip to content

Commit 1ee809a

Browse files
thomasp85hadley
authored andcommitted
Add announcement as vignette (#1779)
* Add announcement as vignette * Move announcement to news subfolder and rename
1 parent ce3f435 commit 1ee809a

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

vignettes/news/2-2-0.Rmd

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# ggplot2 2.2.0
2+
3+
```{r, include=FALSE}
4+
library(ggplot2)
5+
library(dplyr)
6+
library(forcats)
7+
```
8+
9+
10+
I'm very pleased to announce the release of ggplot2 version 2.2.0. Compared to the [latest release](https://blog.rstudio.org/2016/03/03/ggplot2-2-1-0/), this release is a relatively big one, including a large rewrite of the facetting and rendering codebase as well as fixing of numerous bugs and addition of small but notable features. Below I'll describe the most important changes:
11+
12+
## Facets
13+
The facet and layout implementation has been moved to ggproto and received a large rewrite and refactoring. Along with this comes the possibility of writing facet extensions to modify the current facetting possibilities or create entirely new ones. A section in the *Extending ggplot2* vignette regarding facet extensions has been added that describes how to both modify existing facetting and create new ones from scratch.
14+
15+
Along with the rewrite a number of features and improvements has been added, most notably:
16+
17+
* Facetting formulas are now true expressions allowing for much more powerful data facetting, e.g.:
18+
19+
```{r}
20+
ggplot(diamonds, aes(carat, price)) +
21+
geom_point() +
22+
facet_wrap(~cut(depth, 9))
23+
```
24+
25+
* When the number of panels in `facet_wrap()` does not match the dimension of the grid, the axes below hanging panels were dropped in prior versions of ggplot2. Now, an axis is positioned beneath the hanging panels making interpretation of the plot much easier.
26+
27+
```{r}
28+
ggplot(diamonds, aes(carat, price)) +
29+
geom_point() +
30+
facet_wrap(~cut(depth, 7))
31+
```
32+
33+
* As part of the rewrite the axis rendering code received and update as well. It is now possible to set the position of the axes through the `position` argument in the scale constructor:
34+
35+
```{r}
36+
ggplot(diamonds, aes(carat, price)) +
37+
geom_point() +
38+
scale_x_continuous(position = "top")
39+
```
40+
41+
* It is now possible to display a secondary axis that is a linear transformation of the primary axis through the `sec.axis` argument:
42+
43+
```{r}
44+
ggplot(diamonds, aes(carat, price)) +
45+
geom_point() +
46+
scale_x_continuous(position = "top") +
47+
scale_y_continuous("Price ($)", sec.axis = sec_axis(~. * 0.9, name = "Price (€)"))
48+
```
49+
50+
* Strips can now be positioned on any side, and the placement of strips in relation to axes can be controlled using the `strip.placement` theme option e.g.:
51+
52+
```{r}
53+
p <- ggplot(diamonds, aes(carat, price)) +
54+
geom_point() +
55+
facet_wrap(~cut(depth, 2), strip.position = "left")
56+
57+
p + theme(strip.placement = "inside")
58+
p + theme(strip.placement = "outside")
59+
```
60+
61+
62+
## Theming
63+
The theming system has seen an overhaul.
64+
65+
* Blank elements can now be overridden again so you get the expected behavior when setting e.g. `axis.line.x`. Furthermore, `element_line()` gets an `arrow` argument that lets you put arrows on e.g. axes. All in all you can now do stuff like:
66+
67+
```{r}
68+
ggplot(diamonds, aes(carat, price)) +
69+
geom_point() +
70+
theme_minimal() +
71+
theme(
72+
axis.line.y = element_line(arrow = arrow()),
73+
axis.line.x = element_line(arrow = arrow())
74+
)
75+
```
76+
77+
* The user now has increased control over the styling of legends. The whole legend area can be aligned according to the plot area and a box can be drawn around all legends:
78+
79+
```{r}
80+
ggplot(diamonds, aes(carat, price, size = depth, colour = cut)) +
81+
geom_point() +
82+
theme(
83+
legend.justification = "top",
84+
legend.box.margin = margin(3, 3, 3, 3, "mm"),
85+
legend.box.background = element_rect()
86+
)
87+
```
88+
89+
* `panel.margin` and `legend.margin` has been renamed to `panel.spacing` and `legend.spacing` respectively as this was what they were setting all along. A new `legend.margin` has been introduced that actually controls the margin around each legend rather than their spacing.
90+
91+
* The default themes has seen some tweaking making them better match `theme_grey()` and some defaults has been changed (title and legend justification being the most obvious).
92+
93+
* Lastly, the `theme()` function now has named arguments rather than an ellipsis adding support for autocomplete/suggestions
94+
95+
## Minor additions
96+
* `position_stack()` and `position_fill()` now stacks values in reverse order, making the default stack order match the order in the legend. Furthermore, there is now support for stacking negative values. Negative values will be stacked separately from the positive end descend from the x-axis underneath the positive values. e.g.
97+
98+
```{r}
99+
diamond_price <- diamonds %>%
100+
group_by(cut, color) %>%
101+
summarise(price = mean(price)) %>%
102+
ungroup() %>%
103+
mutate(price_dev = price - mean(price))
104+
105+
ggplot(diamond_price) +
106+
geom_col(aes(x = cut, y = price, fill = color), position = "stack")
107+
108+
ggplot(diamond_price) +
109+
geom_col(aes(x = cut, y = price_dev, fill = color), position = "stack")
110+
```
111+
112+
As can be seen the overall ordering cannot necessarily be matched in the presence of negative values, but the ordering on either side of the x-axis will match. If you need the ordering during stacking to work as before, the [forcats](https://cran.r-project.org/web/packages/forcats/index.html) has just been released and provide a number of utility functions to manipulate factors. Use e.g. `fct_rev()`:
113+
114+
```{r}
115+
ggplot(diamond_price) +
116+
geom_col(aes(x = cut, y = price, fill = forcats::fct_rev(color)), position = "stack")
117+
```
118+
119+
* ggplot2 now has support for subtitles and captions. Subtitles appear under the title in a smaller font size. The appearance of subtitles can be modified with the `plot.subtitle` argument in `theme()` and can be added using the subtitle argument in either `ggtitle()` or `labs()`. Captions appear below the plot and right justified where data sources etc would usually be placed. The appearance can be changed using `plot.caption` in `theme()`. Captions are added using the `caption` argument in `labs()`.
120+
* `geom_col()` has been added as a shortcut for `geom_bar(..., stat = "identity")`.
121+
122+
* * *
123+
124+
Read the full list of changes including all the bug-fixes in the [release notes](https://github.com/hadley/ggplot2/releases/tag/v2.2.0)

0 commit comments

Comments
 (0)