Skip to content

Commit 7ada465

Browse files
committed
Merge branch 'main' into position_aesthetics
2 parents 5fe2514 + 97edd62 commit 7ada465

28 files changed

+205
-43
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
* Position adjustments can now have auxiliary aesthetics (@teunbrand).
44
* `position_nudge()` gains `nudge_x` and `nudge_y` aesthetics (#3026, #5445).
55
* `position_dodge()` gains `order` aesthetic (#3022, #3345)
6+
* `scale_{x/y}_discrete(continuous.limits)` is a new argument to control the
7+
display range of discrete scales (@teunbrand, #4174, #6259).
8+
* `geom_ribbon()` now appropriately warns about, and removes, missing values
9+
(@teunbrand, #6243).
610
* `guide_*()` can now accept two inside legend theme elements:
711
`legend.position.inside` and `legend.justification.inside`, allowing inside
812
legends to be placed at different positions. Only inside legends with the same

R/coord-polar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' # to demonstrate how these common plots can be described in the
2121
#' # grammar. Use with EXTREME caution.
2222
#'
23-
#' #' # A pie chart = stacked bar chart + polar coordinates
23+
#' # A pie chart = stacked bar chart + polar coordinates
2424
#' pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) +
2525
#' geom_bar(width = 1)
2626
#' pie + coord_polar(theta = "y")

R/coord-radial.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' @param end Position from 12 o'clock in radians where plot ends, to allow
55
#' for partial polar coordinates. The default, `NULL`, is set to
66
#' `start + 2 * pi`.
7-
#' @param expand If `TRUE`, the default, adds a small expansion factor the
7+
#' @param expand If `TRUE`, the default, adds a small expansion factor to
88
#' the limits to prevent overlap between data and axes. If `FALSE`, limits
99
#' are taken directly from the scale.
1010
#' @param r.axis.inside One of the following:
@@ -27,10 +27,10 @@
2727
#' @param r_axis_inside,rotate_angle `r lifecycle::badge("deprecated")`
2828
#'
2929
#' @note
30-
#' In `coord_radial()`, position guides are can be defined by using
30+
#' In `coord_radial()`, position guides can be defined by using
3131
#' `guides(r = ..., theta = ..., r.sec = ..., theta.sec = ...)`. Note that
3232
#' these guides require `r` and `theta` as available aesthetics. The classic
33-
#' `guide_axis()` can be used for the `r` positions and `guide_axis_theta()` can
33+
#' [guide_axis()] can be used for the `r` positions and [guide_axis_theta()] can
3434
#' be used for the `theta` positions. Using the `theta.sec` position is only
3535
#' sensible when `inner.radius > 0`.
3636
#'

R/fortify-map.R

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#' Fortify method for map objects
22
#'
3+
#' @description
4+
#' `r lifecycle::badge("deprecated")`
5+
#'
36
#' This function turns a map into a data frame that can more easily be
47
#' plotted with ggplot2.
58
#'
@@ -24,6 +27,9 @@
2427
#' geom_polygon(aes(group = group), colour = "white")
2528
#' }
2629
fortify.map <- function(model, data, ...) {
30+
lifecycle::deprecate_warn(
31+
"3.6.0", I("`fortify(<map>)`"), "map_data()"
32+
)
2733
df <- data_frame0(
2834
long = model$x,
2935
lat = model$y,
@@ -46,10 +52,10 @@ fortify.map <- function(model, data, ...) {
4652
#' for plotting with ggplot2.
4753
#'
4854
#' @param map name of map provided by the \pkg{maps} package. These
49-
#' include [maps::county()], [maps::france()],
50-
#' [maps::italy()], [maps::nz()],
51-
#' [maps::state()], [maps::usa()],
52-
#' [maps::world()], [maps::world2()].
55+
#' include [`"county"`][maps::county], [`"france"`][maps::france],
56+
#' [`"italy"`][maps::italy], [`"nz"`][maps::nz],
57+
#' [`"state"`][maps::state], [`"usa"`][maps::usa],
58+
#' [`"world"`][maps::world], or [`"world2"`][maps::world2].
5359
#' @param region name(s) of subregion(s) to include. Defaults to `.` which
5460
#' includes all subregions. See documentation for [maps::map()]
5561
#' for more details.
@@ -80,7 +86,27 @@ fortify.map <- function(model, data, ...) {
8086
map_data <- function(map, region = ".", exact = FALSE, ...) {
8187
check_installed("maps", reason = "for `map_data()`.")
8288
map_obj <- maps::map(map, region, exact = exact, plot = FALSE, fill = TRUE, ...)
83-
fortify(map_obj)
89+
90+
if (!inherits(map_obj, "map")) {
91+
cli::cli_abort(c(
92+
"{.fn maps::map} must return an object of type {.cls map}, not \\
93+
{obj_type_friendly(map_obj)}.",
94+
i = "Did you pass the right arguments?"
95+
))
96+
}
97+
98+
df <- data_frame0(
99+
long = map_obj$x,
100+
lat = map_obj$y,
101+
group = cumsum(is.na(map_obj$x) & is.na(map_obj$y)) + 1,
102+
order = seq_along(map_obj$x),
103+
.size = length(map_obj$x)
104+
)
105+
106+
names <- lapply(strsplit(map_obj$names, "[:,]"), "[", 1:2)
107+
names <- vec_rbind(!!!names, .name_repair = ~ c("region", "subregion"))
108+
df[names(names)] <- vec_slice(names, df$group)
109+
vec_slice(df, stats::complete.cases(df$lat, df$long))
84110
}
85111

86112
#' Create a layer of map borders

R/fortify-spatial.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#' Fortify method for classes from the sp package.
22
#'
3+
#' @description
4+
#' `r lifecycle::badge("deprecated")`
5+
#'
36
#' To figure out the correct variable name for region, inspect
47
#' `as.data.frame(model)`.
58
#'

R/geom-point.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
#' ggplot(mtcars, aes(wt, mpg)) +
8686
#' geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)
8787
#'
88+
#' # The default shape in legends is not filled, but you can override the shape
89+
#' # in the guide to reflect the fill in the legend
90+
#' ggplot(mtcars, aes(wt, mpg, fill = factor(carb), shape = factor(cyl))) +
91+
#' geom_point(size = 5, stroke = 1) +
92+
#' scale_shape_manual(values = 21:25) +
93+
#' scale_fill_ordinal(guide = guide_legend(override.aes = list(shape = 21)))
94+
#'
8895
#' \donttest{
8996
#' # You can create interesting shapes by layering multiple points of
9097
#' # different sizes

R/geom-ribbon.R

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,31 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
126126

127127
draw_key = draw_key_polygon,
128128

129-
handle_na = function(data, params) {
129+
handle_na = function(self, data, params) {
130+
131+
vars <- vapply(
132+
strsplit(self$required_aes, "|", fixed = TRUE),
133+
`[[`, i = 1, character(1)
134+
)
135+
if (params$flipped_aes || any(data$flipped_aes) %||% FALSE) {
136+
vars <- switch_orientation(vars)
137+
}
138+
vars <- c(vars, self$non_missing_aes)
139+
140+
missing <- detect_missing(data, vars, finite = FALSE)
141+
if (!any(missing)) {
142+
return(data)
143+
}
144+
# We're rearranging groups to account for missing values
145+
data$group <- vec_identify_runs(data_frame0(missing, data$group))
146+
data <- vec_slice(data, !missing)
147+
148+
if (!params$na.rm) {
149+
cli::cli_warn(
150+
"Removed {sum(missing)} row{?s} containing missing values or values \\
151+
outside the scale range ({.fn {snake_class(self)}})."
152+
)
153+
}
130154
data
131155
},
132156

@@ -135,7 +159,6 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
135159
flipped_aes = FALSE, outline.type = "both") {
136160
data <- check_linewidth(data, snake_class(self))
137161
data <- flip_data(data, flipped_aes)
138-
if (na.rm) data <- data[stats::complete.cases(data[c("x", "ymin", "ymax")]), ]
139162
data <- data[order(data$group), ]
140163

141164
# Check that aesthetics are constant

R/guide-axis-stack.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ NULL
2222
#' @export
2323
#'
2424
#' @examples
25-
#' #' # A standard plot
25+
#' # A standard plot
2626
#' p <- ggplot(mpg, aes(displ, hwy)) +
2727
#' geom_point() +
2828
#' theme(axis.line = element_line())

R/guides-.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ NULL
6868
#' }
6969
guides <- function(...) {
7070
args <- list2(...)
71-
if (length(args) > 0) {
72-
if (is.list(args[[1]]) && !is.guide(args[[1]])) args <- args[[1]]
73-
args <- rename_aes(args)
71+
# If there are no guides do nothing
72+
if (length(args) == 0) {
73+
return(NULL)
7474
}
7575

76+
if (is.list(args[[1]]) && !inherits(args[[1]], "guide")) args <- args[[1]]
77+
args <- rename_aes(args)
78+
7679
idx_false <- vapply(args, isFALSE, FUN.VALUE = logical(1L))
7780
if (isTRUE(any(idx_false))) {
7881
deprecate_warn0("3.3.4", "guides(`<scale>` = 'cannot be `FALSE`. Use \"none\" instead')")
@@ -84,11 +87,6 @@ guides <- function(...) {
8487
return(guides_list(guides = args))
8588
}
8689

87-
# If there are no guides, do nothing
88-
if (length(args) == 0) {
89-
return(NULL)
90-
}
91-
9290
# Raise warning about unnamed guides
9391
nms <- names(args)
9492
if (is.null(nms)) {

R/limits.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#' scales. By default, any values outside the limits specified are replaced with
55
#' `NA`. Be warned that this will remove data outside the limits and this can
66
#' produce unintended results. For changing x or y axis limits \strong{without}
7-
#' dropping data observations, see [coord_cartesian()].
7+
#' dropping data observations, see
8+
#' [`coord_cartesian(xlim, ylim)`][coord_cartesian], or use a full scale with
9+
#' [`oob = scales::oob_keep`][scales::oob_keep].
810
#'
911
#' @param ... For `xlim()` and `ylim()`: Two numeric values, specifying the left/lower
1012
#' limit and the right/upper limit of the scale. If the larger value is given first,

0 commit comments

Comments
 (0)