Skip to content

Commit 9e1305f

Browse files
committed
merge master into theme_geom
Merge remote-tracking branch 'upstream/master' into theme_geom # Conflicts: # R/theme.r # man/element.Rd # man/theme.Rd
2 parents 42acbd3 + 4d2ca99 commit 9e1305f

Some content is hidden

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

99 files changed

+813
-650
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ export(scale_y_time)
507507
export(sec_axis)
508508
export(set_last_plot)
509509
export(should_stop)
510+
export(standardise_aes_names)
510511
export(stat)
511512
export(stat_bin)
512513
export(stat_bin2d)

NEWS.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
# ggplot2 3.0.0.9000
22

3+
* All `geom_*()` now display an informative error message when required
4+
aesthetics are missing (@dpseidel, #2637 and #2706).
5+
6+
* `sec_axis()` and `dup_axis()` now return appropriate breaks for the secondary
7+
axis when applied to log transformed scales (@dpseidel, #2729).
8+
9+
* `sec_axis()` now works as expected when used in combination with tidy eval
10+
(@dpseidel, #2788).
11+
12+
* `stat_contour()`, `stat_density2d()`, `stat_bin2d()`, `stat_binhex()`
13+
now calculate normalized statistics including `nlevel`, `ndensity`, and
14+
`ncount`. Also, `stat_density()` now includes the calculated statistic
15+
`nlevel`, an alias for `scaled`, to better match the syntax of `stat_bin()`
16+
(@bjreisman, #2679).
17+
318
* `geom_hex()` now understands the `size` and `linetype` aesthetics
419
(@mikmart, #2488).
520

621
* Data is no longer internally reordered when faceting. This makes it safer to
722
feed data columns into `aes()` or into parameters of geoms or stats. However,
823
doing so remains discouraged (@clauswilke).
24+
25+
* `ggsave()` now exits without creating a new graphics device if previously
26+
none was open (@clauswilke, #2363).
927

28+
* Aesthetic names are now consistently standardised both in `aes()` and in the
29+
`aesthetics` argument of scale functions. Also, the US spelling "color"
30+
is now always internally converted to "colour", even when part of a longer
31+
aesthetic name (e.g., `point_color`) (@clauswilke, #2649).
1032

1133
# ggplot2 3.0.0
1234

R/aes.r

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ NULL
77
#' properties (aesthetics) of geoms. Aesthetic mappings can be set in
88
#' [ggplot2()] and in individual layers.
99
#'
10-
#' This function also standardises aesthetic names by performing partial
11-
#' matching, converting color to colour, and translating old style R names to
12-
#' ggplot names (e.g. pch to shape, cex to size).
10+
#' This function also standardises aesthetic names by converting `color` to `colour`
11+
#' (also in substrings, e.g. `point_color` to `point_colour`) and translating old style
12+
#' R names to ggplot names (eg. `pch` to `shape`, `cex` to `size`).
1313
#'
1414
#' @section Quasiquotation:
1515
#'
@@ -143,13 +143,34 @@ print.uneval <- function(x, ...) {
143143
new_aes(NextMethod())
144144
}
145145

146-
# Rename American or old-style aesthetics name
147-
rename_aes <- function(x) {
148-
# Convert prefixes to full names
149-
full <- match(names(x), ggplot_global$all_aesthetics)
150-
names(x)[!is.na(full)] <- ggplot_global$all_aesthetics[full[!is.na(full)]]
146+
#' Standardise aesthetic names
147+
#'
148+
#' This function standardises aesthetic names by converting `color` to `colour`
149+
#' (also in substrings, e.g. `point_color` to `point_colour`) and translating old style
150+
#' R names to ggplot names (eg. `pch` to `shape`, `cex` to `size`).
151+
#' @param x Character vector of aesthetics names, such as `c("colour", "size", "shape")`.
152+
#' @return Character vector of standardised names.
153+
#' @keywords internal
154+
#' @export
155+
standardise_aes_names <- function(x) {
156+
# convert US to UK spelling of colour
157+
x <- sub("color", "colour", x, fixed = TRUE)
151158

152-
plyr::rename(x, ggplot_global$base_to_ggplot, warn_missing = FALSE)
159+
# convert old-style aesthetics names to ggplot version
160+
plyr::revalue(x, ggplot_global$base_to_ggplot, warn_missing = FALSE)
161+
}
162+
163+
# x is a list of aesthetic mappings, as generated by aes()
164+
rename_aes <- function(x) {
165+
names(x) <- standardise_aes_names(names(x))
166+
duplicated_names <- names(x)[duplicated(names(x))]
167+
if (length(duplicated_names) > 0L) {
168+
duplicated_message <- paste0(unique(duplicated_names), collapse = ", ")
169+
warning(
170+
"Duplicated aesthetics after name standardisation: ", duplicated_message, call. = FALSE
171+
)
172+
}
173+
x
153174
}
154175

155176
# Look up the scale that should be used for a given aesthetic

R/axis-secondary.R

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
106106

107107
transform_range = function(self, range) {
108108
range <- structure(data.frame(range), names = '.')
109-
f_eval(self$trans, range)
109+
rlang::eval_tidy(rlang::f_rhs(self$trans), data = range)
110110
},
111111

112-
113112
break_info = function(self, range, scale) {
114113
if (self$empty()) return()
115114

@@ -125,29 +124,22 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
125124
stop("transformation for secondary axes must be monotonic")
126125

127126
# Get break info for the secondary axis
128-
new_range <- range(full_range, na.rm = TRUE)
129-
temp_scale <- self$create_scale(new_range)
130-
range_info <- temp_scale$break_info()
131-
132-
# Map the break values back to their correct position on the primary scale
133-
old_val <- lapply(range_info$major_source, function(x) which.min(abs(full_range - x)))
134-
old_val <- old_range[unlist(old_val)]
135-
old_val_trans <- scale$trans$transform(old_val)
136-
range_info$major[] <- round(rescale(scale$map(old_val_trans, range(old_val_trans)), from = range), digits = 3)
137-
127+
new_range <- range(scale$transform(full_range), na.rm = TRUE)
128+
sec_scale <- self$create_scale(new_range, scale)
129+
range_info <- sec_scale$break_info()
138130
names(range_info) <- paste0("sec.", names(range_info))
139131
range_info
140132
},
141133

142134
# Temporary scale for the purpose of calling break_info()
143-
create_scale = function(self, range) {
135+
create_scale = function(self, range, primary) {
144136
scale <- ggproto(NULL, ScaleContinuousPosition,
145137
name = self$name,
146138
breaks = self$breaks,
147139
labels = self$labels,
148140
limits = range,
149141
expand = c(0, 0),
150-
trans = identity_trans()
142+
trans = primary$trans
151143
)
152144
scale$train(range)
153145
scale

R/facet-grid-.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ NULL
33

44
#' Lay out panels in a grid
55
#'
6-
#' `facet_grid` forms a matrix of panels defined by row and column
6+
#' `facet_grid()` forms a matrix of panels defined by row and column
77
#' faceting variables. It is most useful when you have two discrete
88
#' variables, and all combinations of the variables exist in the data.
99
#'

R/geom-abline.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ NULL
2525
#' `size`. They also each have aesthetics that control the position of
2626
#' the line:
2727
#'
28-
#' - `geom_vline`: `xintercept`
29-
#' - `geom_hline`: `yintercept`
30-
#' - `geom_abline`: `slope` and `intercept`
28+
#' - `geom_vline()`: `xintercept`
29+
#' - `geom_hline()`: `yintercept`
30+
#' - `geom_abline()`: `slope` and `intercept`
3131
#'
3232
#' @seealso See [geom_segment()] for a more general approach to
3333
#' adding straight line segments to a plot.

R/geom-boxplot.r

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#' @section Summary statistics:
88
#' The lower and upper hinges correspond to the first and third quartiles
99
#' (the 25th and 75th percentiles). This differs slightly from the method used
10-
#' by the `boxplot` function, and may be apparent with small samples.
10+
#' by the [boxplot()] function, and may be apparent with small samples.
1111
#' See [boxplot.stats()] for for more information on how hinge
12-
#' positions are calculated for `boxplot`.
12+
#' positions are calculated for [boxplot()].
1313
#'
1414
#' The upper whisker extends from the hinge to the largest value no further than
1515
#' 1.5 * IQR from the hinge (where IQR is the inter-quartile range, or distance
@@ -24,7 +24,7 @@
2424
#'
2525
#' @eval rd_aesthetics("geom", "boxplot")
2626
#'
27-
#' @seealso [geom_quantile()] for continuous x,
27+
#' @seealso [geom_quantile()] for continuous `x`,
2828
#' [geom_violin()] for a richer display of the distribution, and
2929
#' [geom_jitter()] for a useful technique for small data.
3030
#' @inheritParams layer
@@ -60,7 +60,6 @@
6060
#' @examples
6161
#' p <- ggplot(mpg, aes(class, hwy))
6262
#' p + geom_boxplot()
63-
#' p + geom_boxplot() + geom_jitter(width = 0.2)
6463
#' p + geom_boxplot() + coord_flip()
6564
#'
6665
#' p + geom_boxplot(notch = TRUE)
@@ -69,6 +68,8 @@
6968
#' # By default, outlier points match the colour of the box. Use
7069
#' # outlier.colour to override
7170
#' p + geom_boxplot(outlier.colour = "red", outlier.shape = 1)
71+
#' # Remove outliers when overlaying boxplot with original data points
72+
#' p + geom_boxplot(outlier.shape = NA) + geom_jitter(width = 0.2)
7273
#'
7374
#' # Boxplots are automatically dodged when any aesthetic is a factor
7475
#' p + geom_boxplot(aes(colour = drv))
@@ -79,6 +80,7 @@
7980
#' geom_boxplot()
8081
#' ggplot(diamonds, aes(carat, price)) +
8182
#' geom_boxplot(aes(group = cut_width(carat, 0.25)))
83+
#' # Adjust the transparency of outliers using outlier.alpha
8284
#' ggplot(diamonds, aes(carat, price)) +
8385
#' geom_boxplot(aes(group = cut_width(carat, 0.25)), outlier.alpha = 0.1)
8486
#'

R/geom-density2d.r

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
#' # set of contours for each value of that variable
3131
#' d + geom_density_2d(aes(colour = cut))
3232
#'
33+
#' # Similarly, if you apply faceting to the plot, contours will be
34+
#' # drawn for each facet, but the levels will calculated across all facets
35+
#' d + stat_density_2d(aes(fill = stat(level)), geom = "polygon") +
36+
#' facet_grid(. ~ cut) + scale_fill_viridis_c()
37+
#' # To override this behavior (for instace, to better visualize the density
38+
#' # within each facet), use stat(nlevel)
39+
#' d + stat_density_2d(aes(fill = stat(nlevel)), geom = "polygon") +
40+
#' facet_grid(. ~ cut) + scale_fill_viridis_c()
41+
#'
3342
#' # If we turn contouring off, we can use use geoms like tiles:
3443
#' d + stat_density_2d(geom = "raster", aes(fill = stat(density)), contour = FALSE)
3544
#' # Or points:

R/geom-histogram.r

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
#'
33
#' Visualise the distribution of a single continuous variable by dividing
44
#' the x axis into bins and counting the number of observations in each bin.
5-
#' Histograms (`geom_histogram`) display the count with bars; frequency
6-
#' polygons (`geom_freqpoly`) display the counts with lines. Frequency
5+
#' Histograms (`geom_histogram()`) display the counts with bars; frequency
6+
#' polygons (`geom_freqpoly()`) display the counts with lines. Frequency
77
#' polygons are more suitable when you want to compare the distribution
88
#' across the levels of a categorical variable.
99
#'
10-
#' `stat_bin` is suitable only for continuous x data. If your x data is
10+
#' `stat_bin()` is suitable only for continuous x data. If your x data is
1111
#' discrete, you probably want to use [stat_count()].
1212
#'
13-
#' By default, the underlying computation (`stat_bin`) uses 30 bins;
13+
#' By default, the underlying computation (`stat_bin()`) uses 30 bins;
1414
#' this is not a good default, but the idea is to get you experimenting with
1515
#' different bin widths. You may need to look at a few to uncover the full
1616
#' story behind your data.
1717
#'
1818
#' @section Aesthetics:
19-
#' `geom_histogram` uses the same aesthetics as [geom_bar()];
20-
#' `geom_freqpoly` uses the same aesthetics as [geom_line()].
19+
#' `geom_histogram()` uses the same aesthetics as [geom_bar()];
20+
#' `geom_freqpoly()` uses the same aesthetics as [geom_line()].
2121
#'
2222
#' @export
2323
#' @inheritParams layer
2424
#' @inheritParams geom_point
2525
#' @param geom,stat Use to override the default connection between
26-
#' `geom_histogram`/`geom_freqpoly` and `stat_bin`.
26+
#' `geom_histogram()`/`geom_freqpoly()` and `stat_bin()`.
2727
#' @examples
2828
#' ggplot(diamonds, aes(carat)) +
2929
#' geom_histogram()

R/geom-point.r

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
#' It can be used to compare one continuous and one categorical variable, or
66
#' two categorical variables, but a variation like [geom_jitter()],
77
#' [geom_count()], or [geom_bin2d()] is usually more
8-
#' appropriate.
9-
#'
10-
#' The \emph{bubblechart} is a scatterplot with a third variable mapped to
11-
#' the size of points. There are no special names for scatterplots where
12-
#' another variable is mapped to point shape or colour, however.
8+
#' appropriate. A _bubblechart_ is a scatterplot with a third variable
9+
#' mapped to the size of points.
1310
#'
1411
#' @section Overplotting:
1512
#' The biggest potential problem with a scatterplot is overplotting: whenever
@@ -47,6 +44,7 @@
4744
#' # Add aesthetic mappings
4845
#' p + geom_point(aes(colour = factor(cyl)))
4946
#' p + geom_point(aes(shape = factor(cyl)))
47+
#' # A "bubblechart":
5048
#' p + geom_point(aes(size = qsec))
5149
#'
5250
#' # Set aesthetics to fixed value

R/geom-smooth.r

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#' Smoothed conditional means
22
#'
33
#' Aids the eye in seeing patterns in the presence of overplotting.
4-
#' `geom_smooth` and `stat_smooth` are effectively aliases: they
5-
#' both use the same arguments. Use `geom_smooth` unless you want to
4+
#' `geom_smooth()` and `stat_smooth()` are effectively aliases: they
5+
#' both use the same arguments. Use `stat_smooth()` if you want to
66
#' display the results with a non-standard geom.
77
#'
88
#' Calculation is performed by the (currently undocumented)
9-
#' `predictdf` generic and its methods. For most methods the standard
9+
#' `predictdf()` generic and its methods. For most methods the standard
1010
#' error bounds are computed using the [predict()] method -- the
11-
#' exceptions are `loess`, which uses a t-based approximation, and
12-
#' `glm`, where the normal confidence interval is constructed on the link
11+
#' exceptions are `loess()`, which uses a t-based approximation, and
12+
#' `glm()`, where the normal confidence interval is constructed on the link
1313
#' scale and then back-transformed to the response scale.
1414
#'
1515
#' @eval rd_aesthetics("geom", "smooth")
1616
#' @inheritParams layer
1717
#' @inheritParams geom_point
1818
#' @param geom,stat Use to override the default connection between
19-
#' `geom_smooth` and `stat_smooth`.
19+
#' `geom_smooth()` and `stat_smooth()`.
2020
#' @seealso See individual modelling functions for more details:
2121
#' [lm()] for linear smooths,
2222
#' [glm()] for generalised linear smooths, and

R/geom-text.r

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Text
22
#'
3-
#' `geom_text` adds text directly to the plot. `geom_label` draws
3+
#' `geom_text()` adds text directly to the plot. `geom_label()` draws
44
#' a rectangle behind the text, making it easier to read.
55
#'
66
#' Note that the "width" and "height" of a text element are 0, so stacking
@@ -10,16 +10,16 @@
1010
#' space they occupy on the plot is not constant in data units: when you
1111
#' resize a plot, labels stay the same size, but the size of the axes changes.
1212
#'
13-
#' `geom_text` and `geom_label` both add a label for each row in the
13+
#' `geom_text()` and `geom_label()` add labels for each row in the
1414
#' data, even if coordinates x, y are set to single values in the call
15-
#' to `geom_label` or `geom_text`.
15+
#' to `geom_label()` or `geom_text()`.
1616
#' To add labels at specified points use [annotate()] with
1717
#' `annotate(geom = "text", ...)` or `annotate(geom = "label", ...)`.
1818
#'
1919
#' @eval rd_aesthetics("geom", "text")
20-
#' @section `geom_label`:
21-
#' Currently `geom_label` does not support the `rot` parameter and
22-
#' is considerably slower than `geom_text`. The `fill` aesthetic
20+
#' @section `geom_label()`:
21+
#' Currently `geom_label()` does not support the `angle` aesthetic and
22+
#' is considerably slower than `geom_text()`. The `fill` aesthetic
2323
#' controls the background colour of the label.
2424
#'
2525
#' @section Alignment:

R/guide-colorbar.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ guide_train.colorbar <- function(guide, scale, aesthetic = NULL) {
218218

219219
# bar specification (number of divs etc)
220220
.limits <- scale$get_limits()
221-
.bar <- seq(.limits[1], .limits[2], length = guide$nbin)
221+
.bar <- seq(.limits[1], .limits[2], length.out = guide$nbin)
222222
if (length(.bar) == 0) {
223223
.bar = unique(.limits)
224224
}

R/guide-legend.r

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#' multiple guides are displayed, not the contents of the guide itself.
5858
#' If 0 (default), the order is determined by a secret algorithm.
5959
#' @param ... ignored.
60-
#' @return A guide object
6160
#' @export
6261
#' @family guides
6362
#' @examples

R/labels.r

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ update_labels <- function(p, labels) {
1919
#' Modify axis, legend, and plot labels
2020
#'
2121
#' Good labels are critical for making your plots accessible to a wider
22-
#' audience. Ensure the axis and legend labels display the full variable name.
23-
#' Use the plot `title` and `subtitle` to explain the main findings.
24-
#' It's common to use the `caption` to provide information about the
25-
#' data source. `tag` can be used for adding identification tags.
22+
#' audience. Always ensure the axis and legend labels display the full
23+
#' variable name. Use the plot `title` and `subtitle` to explain the
24+
#' main findings. It's common to use the `caption` to provide information
25+
#' about the data source. `tag` can be used for adding identification tags
26+
#' to differentiate between multiple plots.
2627
#'
2728
#' You can also set axis and legend labels in the individual scales (using
28-
#' the first argument, the `name`). I recommend doing that if you're
29-
#' changing other scale options.
29+
#' the first argument, the `name`). If you're changing other scale options, this
30+
#' is recommended.
3031
#'
3132
#' @param label The text for the axis, plot title or caption below the plot.
3233
#' @param subtitle the text for the subtitle for the plot which will be

0 commit comments

Comments
 (0)