Skip to content

Commit b456a6b

Browse files
authored
Merge branch 'master' into v3.3.0-rc
2 parents 625a03a + 83c8123 commit b456a6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+494
-206
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ggplot2
2-
Version: 3.3.0
2+
Version: 3.3.0.9000
33
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
44
Description: A system for 'declaratively' creating graphics,
55
based on "The Grammar of Graphics". You provide the data, tell 'ggplot2'

NEWS.md

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* `annotation_raster()` adds support for native rasters. For large rasters,
2+
native rasters render significantly faster than arrays (@kent37, #3388)
3+
4+
* Support graphics devices that use the `file` argument instead of `fileneame`
5+
in `ggsave()` (@bwiernik, #3810)
6+
17
# ggplot2 3.3.0
28

39
This is a minor release but does contain a range of substantial new features,
@@ -372,7 +378,10 @@ as the tidyverse is committed to support 5 major versions of R.
372378

373379
## Breaking changes
374380

375-
This is a minor release and breaking changes have been kept to a minimum. End users of ggplot2 are unlikely to encounter any issues. However, there are a few items that developers of ggplot2 extensions should be aware of. For additional details, see also the discussion accompanying issue #2890.
381+
This is a minor release and breaking changes have been kept to a minimum. End users of
382+
ggplot2 are unlikely to encounter any issues. However, there are a few items that developers
383+
of ggplot2 extensions should be aware of. For additional details, see also the discussion
384+
accompanying issue #2890.
376385

377386
* In non-user-facing internal code (specifically in the `aes()` function and in
378387
the `aesthetics` argument of scale functions), ggplot2 now always uses the British
@@ -972,25 +981,45 @@ This is a minor release and breaking changes have been kept to a minimum. End us
972981
973982
### Subtitle and caption
974983
975-
Thanks to @hrbrmstr plots now have subtitles and captions, which can be set with the `subtitle` and `caption` arguments to `ggtitle()` and `labs()`. You can control their appearance with the theme settings `plot.caption` and `plot.subtitle`. The main plot title is now left-aligned to better work better with a subtitle. The caption is right-aligned (@hrbrmstr).
984+
Thanks to @hrbrmstr plots now have subtitles and captions, which can be set with
985+
the `subtitle` and `caption` arguments to `ggtitle()` and `labs()`. You can
986+
control their appearance with the theme settings `plot.caption` and
987+
`plot.subtitle`. The main plot title is now left-aligned to better work better
988+
with a subtitle. The caption is right-aligned (@hrbrmstr).
976989
977990
### Stacking
978991
979-
`position_stack()` and `position_fill()` now sort the stacking order to match grouping order. This allows you to control the order through grouping, and ensures that the default legend matches the plot (#1552, #1593). If you want the opposite order (useful if you have horizontal bars and horizontal legend), you can request reverse stacking by using `position = position_stack(reverse = TRUE)` (#1837).
992+
`position_stack()` and `position_fill()` now sort the stacking order to match
993+
grouping order. This allows you to control the order through grouping, and
994+
ensures that the default legend matches the plot (#1552, #1593). If you want the
995+
opposite order (useful if you have horizontal bars and horizontal legend), you
996+
can request reverse stacking by using `position = position_stack(reverse = TRUE)`
997+
(#1837).
980998
981-
`position_stack()` and `position_fill()` now accepts negative values which will create stacks extending below the x-axis (#1691).
999+
`position_stack()` and `position_fill()` now accepts negative values which will
1000+
create stacks extending below the x-axis (#1691).
9821001
983-
`position_stack()` and `position_fill()` gain a `vjust` argument which makes it easy to (e.g.) display labels in the middle of stacked bars (#1821).
1002+
`position_stack()` and `position_fill()` gain a `vjust` argument which makes it
1003+
easy to (e.g.) display labels in the middle of stacked bars (#1821).
9841004
9851005
### Layers
9861006
987-
`geom_col()` was added to complement `geom_bar()` (@hrbrmstr). It uses `stat="identity"` by default, making the `y` aesthetic mandatory. It does not support any other `stat_()` and does not provide fallback support for the `binwidth` parameter. Examples and references in other functions were updated to demonstrate `geom_col()` usage.
1007+
`geom_col()` was added to complement `geom_bar()` (@hrbrmstr). It uses
1008+
`stat="identity"` by default, making the `y` aesthetic mandatory. It does not
1009+
support any other `stat_()` and does not provide fallback support for the
1010+
`binwidth` parameter. Examples and references in other functions were updated to
1011+
demonstrate `geom_col()` usage.
9881012
989-
When creating a layer, ggplot2 will warn if you use an unknown aesthetic or an unknown parameter. Compared to the previous version, this is stricter for aesthetics (previously there was no message), and less strict for parameters (previously this threw an error) (#1585).
1013+
When creating a layer, ggplot2 will warn if you use an unknown aesthetic or an
1014+
unknown parameter. Compared to the previous version, this is stricter for
1015+
aesthetics (previously there was no message), and less strict for parameters
1016+
(previously this threw an error) (#1585).
9901017
9911018
### Facetting
9921019
993-
The facet system, as well as the internal panel class, has been rewritten in ggproto. Facets are now extendable in the same manner as geoms and stats, as described in `vignette("extending-ggplot2")`.
1020+
The facet system, as well as the internal panel class, has been rewritten in
1021+
ggproto. Facets are now extendable in the same manner as geoms and stats, as
1022+
described in `vignette("extending-ggplot2")`.
9941023
9951024
We have also added the following new fatures.
9961025
@@ -1012,7 +1041,10 @@ We have also added the following new fatures.
10121041
10131042
### Extensions
10141043
1015-
Unfortunately there was a major oversight in the construction of ggproto which lead to extensions capturing the super object at package build time, instead of at package run time (#1826). This problem has been fixed, but requires re-installation of all extension packages.
1044+
Unfortunately there was a major oversight in the construction of ggproto which
1045+
lead to extensions capturing the super object at package build time, instead of
1046+
at package run time (#1826). This problem has been fixed, but requires
1047+
re-installation of all extension packages.
10161048
10171049
## Scales
10181050
@@ -1047,7 +1079,10 @@ Unfortunately there was a major oversight in the construction of ggproto which l
10471079
10481080
### Discrete scales
10491081
1050-
The treatment of missing values by discrete scales has been thoroughly overhauled (#1584). The underlying principle is that we can naturally represent missing values on discrete variables (by treating just like another level), so by default we should.
1082+
The treatment of missing values by discrete scales has been thoroughly
1083+
overhauled (#1584). The underlying principle is that we can naturally represent
1084+
missing values on discrete variables (by treating just like another level), so
1085+
by default we should.
10511086
10521087
This principle applies to:
10531088
@@ -1378,7 +1413,8 @@ There were a number of tweaks to the theme elements that control legends:
13781413
13791414
### Extensibility
13801415
1381-
There is now an official mechanism for defining Stats, Geoms, and Positions in other packages. See `vignette("extending-ggplot2")` for details.
1416+
There is now an official mechanism for defining Stats, Geoms, and Positions in
1417+
other packages. See `vignette("extending-ggplot2")` for details.
13821418
13831419
* All Geoms, Stats and Positions are now exported, so you can inherit from them
13841420
when making your own objects (#989).
@@ -1449,7 +1485,7 @@ A number of geoms have been renamed to be internally consistent:
14491485
to `geom_density_2d()`/`stat_density_2d()`.
14501486
14511487
* `stat_spoke()` is now `geom_spoke()` since I realised it's a
1452-
reparameterisation of `geom_segment().
1488+
reparameterisation of `geom_segment()`.
14531489

14541490
* `stat_bindot()` has been removed because it's so tightly coupled to
14551491
`geom_dotplot()`. If you happened to use `stat_bindot()`, just change to
@@ -1618,7 +1654,7 @@ version of ggplot.
16181654

16191655
* `geom_smooth()` gains explicit `method`, `se` and `formula` arguments.
16201656

1621-
* `geom_histogram()` gains `binwidth`, `bins`, origin` and `right`
1657+
* `geom_histogram()` gains `binwidth`, `bins`, `origin` and `right`
16221658
arguments.
16231659

16241660
* `geom_jitter()` gains `width` and `height` arguments to make it easier

R/aes.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ is_position_aes <- function(vars) {
226226
#' [substitute()] to generate a call to `aes()`.
227227
#'
228228
#' I recommend using `aes_()`, because creating the equivalents of
229-
#' `aes(colour = "my colour")` or \code{aes{x = `X$1`}}
229+
#' `aes(colour = "my colour")` or \code{aes(x = `X$1`)}
230230
#' with `aes_string()` is quite clunky.
231231
#'
232232
#'

R/annotation-raster.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NULL
1010
#' of the raster, and the raster must already have its own colours). This
1111
#' is useful for adding bitmap images.
1212
#'
13-
#' @param raster raster object to display
13+
#' @param raster raster object to display, may be an `array` or a `nativeRaster`
1414
#' @param xmin,xmax x location (in data coordinates) giving horizontal
1515
#' location of raster
1616
#' @param ymin,ymax y location (in data coordinates) giving vertical
@@ -39,7 +39,8 @@ NULL
3939
#' geom_point()
4040
annotation_raster <- function(raster, xmin, xmax, ymin, ymax,
4141
interpolate = FALSE) {
42-
raster <- grDevices::as.raster(raster)
42+
if (!inherits(raster, 'nativeRaster'))
43+
raster <- grDevices::as.raster(raster)
4344

4445
layer(
4546
data = dummy_data(),

R/geom-bar.r

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
#' Bar charts
22
#'
33
#' There are two types of bar charts: `geom_bar()` and `geom_col()`.
4-
#' `geom_bar()` makes the height of the
5-
#' bar proportional to the number of cases in each group (or if the
6-
#' `weight` aesthetic is supplied, the sum of the weights). If you want the
7-
#' heights of the bars to represent values in the data, use
8-
#' `geom_col()` instead. `geom_bar()` uses `stat_count()` by
4+
#' `geom_bar()` makes the height of the bar proportional to the number of
5+
#' cases in each group (or if the `weight` aesthetic is supplied, the sum
6+
#' of the weights). If you want the heights of the bars to represent values
7+
#' in the data, use `geom_col()` instead. `geom_bar()` uses `stat_count()` by
98
#' default: it counts the number of cases at each x position. `geom_col()`
109
#' uses `stat_identity()`: it leaves the data as is.
1110
#'
1211
#' A bar chart uses height to represent a value, and so the base of the
13-
#' bar must always be shown to produce a valid visual comparison. This is why
14-
#' it doesn't make sense to use a log-scaled y axis with a bar chart.
12+
#' bar must always be shown to produce a valid visual comparison.
13+
#' Proceed with caution when using transformed scales with a bar chart.
14+
#' It's important to always use a meaningful reference point for the base of the bar.
15+
#' For example, for log transformations the reference point is 1. In fact, when
16+
#' using a log scale, `geom_bar()` automatically places the base of the bar at 1.
17+
#' Furthermore, never use stacked bars with a transformed scale, because scaling
18+
#' happens before stacking. As a consequence, the height of bars will be wrong
19+
#' when stacking occurs with a transformed scale.
1520
#'
1621
#' By default, multiple bars occupying the same `x` position will be stacked
1722
#' atop one another by [position_stack()]. If you want them to be dodged
1823
#' side-to-side, use [position_dodge()] or [position_dodge2()]. Finally,
19-
#' [position_fill()] shows relative proportions at each `x` by stacking the bars
20-
#' and then standardising each bar to have the same height.
24+
#' [position_fill()] shows relative proportions at each `x` by stacking the
25+
#' bars and then standardising each bar to have the same height.
2126
#'
2227
#' @eval rd_orientation()
2328
#'
@@ -36,9 +41,6 @@
3641
#' rare event that this fails it can be given explicitly by setting `orientation`
3742
#' to either `"x"` or `"y"`. See the *Orientation* section for more detail.
3843
#' @param width Bar width. By default, set to 90% of the resolution of the data.
39-
#' @param binwidth `geom_bar()` no longer has a binwidth argument - if
40-
#' you use it you'll get an warning telling to you use
41-
#' [geom_histogram()] instead.
4244
#' @param geom,stat Override the default connection between `geom_bar()` and
4345
#' `stat_count()`.
4446
#' @examples
@@ -82,19 +84,10 @@ geom_bar <- function(mapping = NULL, data = NULL,
8284
stat = "count", position = "stack",
8385
...,
8486
width = NULL,
85-
binwidth = NULL,
8687
na.rm = FALSE,
8788
orientation = NA,
8889
show.legend = NA,
8990
inherit.aes = TRUE) {
90-
91-
if (!is.null(binwidth)) {
92-
warn("`geom_bar()` no longer has a `binwidth` parameter. Please use `geom_histogram()` instead.")
93-
return(geom_histogram(mapping = mapping, data = data,
94-
position = position, width = width, binwidth = binwidth, ...,
95-
na.rm = na.rm, show.legend = show.legend, inherit.aes = inherit.aes))
96-
}
97-
9891
layer(
9992
data = data,
10093
mapping = mapping,

R/geom-histogram.r

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#' one change at a time. You may need to look at a few options to uncover
1818
#' the full story behind your data.
1919
#'
20+
#' In addition to `geom_histogram`, you can create a histogram plot by using
21+
#' `scale_x_binned()` with [geom_bar()]. This method by default plots tick marks
22+
#' in between each bar. .
23+
#'
2024
#' @eval rd_orientation()
2125
#'
2226
#' @section Aesthetics:
@@ -39,6 +43,12 @@
3943
#' ggplot(diamonds, aes(y = carat)) +
4044
#' geom_histogram()
4145
#'
46+
#' # For histograms with tick marks between each bin, use `geom_bar` with
47+
#' # `scale_x_binned`.
48+
#' ggplot(diamonds, aes(carat)) +
49+
#' geom_bar() +
50+
#' scale_x_binned()
51+
#'
4252
#' # Rather than stacking histograms, it's easier to compare frequency
4353
#' # polygons
4454
#' ggplot(diamonds, aes(price, fill = cut)) +

R/geom-text.r

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
#' Text
22
#'
3-
#' `geom_text()` adds text directly to the plot. `geom_label()` draws
4-
#' a rectangle behind the text, making it easier to read.
5-
#'
6-
#' Note that the "width" and "height" of a text element are 0, so stacking
7-
#' and dodging text will not work by default, and axis limits are not
8-
#' automatically expanded to include all text. Obviously, labels do have
9-
#' height and width, but they are physical units, not data units. The amount of
10-
#' space they occupy on the plot is not constant in data units: when you
11-
#' resize a plot, labels stay the same size, but the size of the axes changes.
3+
#' Text geoms are useful for labeling plots. They can be used by themselves as
4+
#' scatterplots or in cobination with other geoms, for example, for labeling
5+
#' points or for annotating the height of bars. `geom_text()` adds only text
6+
#' to the plot. `geom_label()` draws a rectangle behind the text, making it
7+
#' easier to read.
8+
#'
9+
#' Note that when you resize a plot, text labels stay the same size, even
10+
#' though the size of the plot area changes. This happens because the "width"
11+
#' and "height" of a text element are 0. Obviously, text labels do have height
12+
#' and width, but they are physical units, not data units. For the same reason,
13+
#' stacking and dodging text will not work by default, and axis limits are not
14+
#' automatically expanded to include all text.
1215
#'
1316
#' `geom_text()` and `geom_label()` add labels for each row in the
1417
#' data, even if coordinates x, y are set to single values in the call
1518
#' to `geom_label()` or `geom_text()`.
1619
#' To add labels at specified points use [annotate()] with
1720
#' `annotate(geom = "text", ...)` or `annotate(geom = "label", ...)`.
1821
#'
22+
#' To automatically position non-overlapping text labels see the
23+
#' \href{https://cran.r-project.org/package=ggrepel}{ggrepel}
24+
#' package.
25+
#'
1926
#' @eval rd_aesthetics("geom", "text")
2027
#' @section `geom_label()`:
2128
#' Currently `geom_label()` does not support the `angle` aesthetic and
@@ -36,8 +43,14 @@
3643
#' displayed as described in `?plotmath`.
3744
#' @param nudge_x,nudge_y Horizontal and vertical adjustment to nudge labels by.
3845
#' Useful for offsetting text from points, particularly on discrete scales.
46+
#' Cannot be jointy specified with `position`.
47+
#' @param position Position adjustment, either as a string, or the result of
48+
#' a call to a position adjustment function. Cannot be jointy specified with
49+
#' `nudge_x` or `nudge_y`.
3950
#' @param check_overlap If `TRUE`, text that overlaps previous text in the
40-
#' same layer will not be plotted.
51+
#' same layer will not be plotted. `check_overlap` happens at draw time and in
52+
#' the order of the data. Therefore data should be arranged by the label
53+
#' column before calling `geom_label()` or `geom_text()`.
4154
#' @export
4255
#' @examples
4356
#' p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars)))

R/labeller.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ labeller <- function(..., .rows = NULL, .cols = NULL,
440440
labellers <- lapply(dots, as_labeller)
441441
} else {
442442
margin_labeller <- as_labeller(margin_labeller, default = .default,
443-
multi_line = .multi_line)
443+
multi_line = .multi_line)
444444

445445
# Check that variable-specific labellers do not overlap with
446446
# margin-wide labeller
@@ -510,8 +510,8 @@ build_strip <- function(label_df, labeller, theme, horizontal) {
510510
theme, horizontal, clip = "on")
511511

512512
grobs_bottom <- lapply(labels, element_render, theme = theme,
513-
element = "strip.text.x.bottom", margin_x = TRUE,
514-
margin_y = TRUE)
513+
element = "strip.text.x.bottom", margin_x = TRUE,
514+
margin_y = TRUE)
515515
grobs_bottom <- assemble_strips(matrix(grobs_bottom, ncol = ncol, nrow = nrow),
516516
theme, horizontal, clip = "on")
517517

R/layout.R

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,13 @@ scale_apply <- function(data, vars, method, scale_id, scales) {
296296
abort("`scale_id` must not be `NA`")
297297
}
298298

299-
scale_index <- unname(split(
300-
seq_along(scale_id),
301-
factor(scale_id, levels = seq_along(scales))
302-
))
299+
scale_index <- split_with_index(seq_along(scale_id), scale_id, length(scales))
303300

304301
lapply(vars, function(var) {
305302
pieces <- lapply(seq_along(scales), function(i) {
306303
scales[[i]][[method]](data[[var]][scale_index[[i]]])
307304
})
308-
# Join pieces back together, if necessary
309-
if (!is.null(pieces)) {
310-
unlist(pieces)[order(unlist(scale_index))]
311-
}
305+
o <- order(unlist(scale_index))[seq_len(sum(lengths(pieces)))]
306+
do.call("c", pieces)[o]
312307
})
313308
}

R/legend-draw.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ draw_key_path <- function(data, params, size) {
137137
segmentsGrob(0.1, 0.5, 0.9, 0.5,
138138
gp = gpar(
139139
col = alpha(data$colour %||% data$fill %||% "black", data$alpha),
140+
fill = alpha(params$arrow.fill %||% data$colour
141+
%||% data$fill %||% "black", data$alpha),
140142
lwd = (data$size %||% 0.5) * .pt,
141143
lty = data$linetype %||% 1,
142144
lineend = "butt"

0 commit comments

Comments
 (0)