Skip to content

Commit

Permalink
Merge branch 'main' into text_key_size
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand authored Dec 8, 2023
2 parents ac47e4c + 5edfbbe commit 8863d83
Show file tree
Hide file tree
Showing 215 changed files with 3,258 additions and 833 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Imports:
MASS,
mgcv,
rlang (>= 1.1.0),
scales (>= 1.2.0),
scales (>= 1.3.0),
stats,
tibble,
vctrs (>= 0.5.0),
Expand Down Expand Up @@ -176,11 +176,13 @@ Collate:
'guide-.R'
'guide-axis.R'
'guide-axis-logticks.R'
'guide-axis-stack.R'
'guide-axis-theta.R'
'guide-legend.R'
'guide-bins.R'
'guide-colorbar.R'
'guide-colorsteps.R'
'guide-custom.R'
'layer.R'
'guide-none.R'
'guide-old.R'
Expand Down Expand Up @@ -273,6 +275,7 @@ Collate:
'utilities-grid.R'
'utilities-help.R'
'utilities-matrix.R'
'utilities-patterns.R'
'utilities-resolution.R'
'utilities-tidy-eval.R'
'zxx.R'
Expand Down
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ S3method(makeContext,dotstackGrob)
S3method(merge_element,default)
S3method(merge_element,element)
S3method(merge_element,element_blank)
S3method(pattern_alpha,GridPattern)
S3method(pattern_alpha,GridTilingPattern)
S3method(pattern_alpha,default)
S3method(pattern_alpha,list)
S3method(plot,ggplot)
S3method(predictdf,default)
S3method(predictdf,glm)
Expand Down Expand Up @@ -148,6 +152,8 @@ S3method(widthDetails,zeroGrob)
export("%+%")
export("%+replace%")
export(.data)
export(.expose_data)
export(.ignore_data)
export(.pt)
export(.stroke)
export(AxisSecondary)
Expand Down Expand Up @@ -214,9 +220,11 @@ export(GeomVline)
export(Guide)
export(GuideAxis)
export(GuideAxisLogticks)
export(GuideAxisStack)
export(GuideBins)
export(GuideColourbar)
export(GuideColoursteps)
export(GuideCustom)
export(GuideLegend)
export(GuideNone)
export(GuideOld)
Expand Down Expand Up @@ -352,6 +360,7 @@ export(expr)
export(facet_grid)
export(facet_null)
export(facet_wrap)
export(fill_alpha)
export(find_panel)
export(flip_data)
export(flipped_names)
Expand Down Expand Up @@ -423,12 +432,14 @@ export(ggsave)
export(ggtitle)
export(guide_axis)
export(guide_axis_logticks)
export(guide_axis_stack)
export(guide_axis_theta)
export(guide_bins)
export(guide_colorbar)
export(guide_colorsteps)
export(guide_colourbar)
export(guide_coloursteps)
export(guide_custom)
export(guide_gengrob)
export(guide_geom)
export(guide_legend)
Expand Down Expand Up @@ -472,6 +483,7 @@ export(new_guide)
export(old_guide)
export(panel_cols)
export(panel_rows)
export(pattern_alpha)
export(position_dodge)
export(position_dodge2)
export(position_fill)
Expand Down
26 changes: 26 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

* `draw_key_label()` now better reflects the appearance of labels.

* The `minor_breaks` function argument in scales can now take a function with
two arguments: the scale's limits and the scale's major breaks (#3583).

* (internal) The `ScaleContinuous$get_breaks()` method no longer censors
the computed breaks.

* Plot scales now ignore `AsIs` objects constructed with `I(x)`, instead of
invoking the identity scale. This allows these columns to co-exist with other
layers that need a non-identity scale for the same aesthetic. Also, it makes
it easy to specify relative positions (@teunbrand, #5142).

* The `fill` aesthetic in many geoms now accepts grid's patterns and gradients.
For developers of layer extensions, this feature can be enabled by switching
from `fill = alpha(fill, alpha)` to `fill = fill_alpha(fill, alpha)` when
providing fills to `grid::gpar()` (@teunbrand, #3997).

* The plot's title, subtitle and caption now obey horizontal text margins
(#5533).

* New `guide_axis_stack()` to combine other axis guides on top of one another.

* New `guide_custom()` function for drawing custom graphical objects (grobs)
unrelated to scales in legend positions (#5416).

* `theme()` now supports splicing a list of arguments (#5542).

* Contour functions will not fail when `options("OutDec")` is not `.` (@eliocamp, #5555).

* The `legend.key` theme element is set to inherit from the `panel.background`
Expand Down
2 changes: 1 addition & 1 deletion R/aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ alternative_aes_extract_usage <- function(x) {
} else if (is_call(x, "$")) {
as.character(x[[3]])
} else {
cli::cli_abort("Don't know how to get alternative usage for {.var {x}}")
cli::cli_abort("Don't know how to get alternative usage for {.var {x}}.")
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/annotation-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GeomCustomAnn <- ggproto("GeomCustomAnn", Geom,
draw_panel = function(data, panel_params, coord, grob, xmin, xmax,
ymin, ymax) {
if (!inherits(coord, "CoordCartesian")) {
cli::cli_abort("{.fn annotation_custom} only works with {.fn coord_cartesian}")
cli::cli_abort("{.fn annotation_custom} only works with {.fn coord_cartesian}.")
}
corners <- data_frame0(
x = c(xmin, xmax),
Expand Down
2 changes: 1 addition & 1 deletion R/annotation-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ annotation_map <- function(map, ...) {
if (!is.null(map$long)) map$x <- map$long
if (!is.null(map$region)) map$id <- map$region
if (!all(c("x", "y", "id") %in% names(map))) {
cli::cli_abort("{.arg map} must have the columns {.col x}, {.col y}, and {.col id}")
cli::cli_abort("{.arg map} must have the columns {.col x}, {.col y}, and {.col id}.")
}

layer(
Expand Down
2 changes: 1 addition & 1 deletion R/annotation-raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ GeomRasterAnn <- ggproto("GeomRasterAnn", Geom,
draw_panel = function(data, panel_params, coord, raster, xmin, xmax,
ymin, ymax, interpolate = FALSE) {
if (!inherits(coord, "CoordCartesian")) {
cli::cli_abort("{.fn annotation_raster} only works with {.fn coord_cartesian}")
cli::cli_abort("{.fn annotation_raster} only works with {.fn coord_cartesian}.")
}
corners <- data_frame0(
x = c(xmin, xmax),
Expand Down
2 changes: 1 addition & 1 deletion R/annotation.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
#' @section Unsupported geoms:
#' Due to their special nature, reference line geoms [geom_abline()],
#' [geom_hline()], and [geom_vline()] can't be used with [annotate()].
#' [geom_hline()], and [geom_vline()] can't be used with `annotate()`.
#' You can use these geoms directly for annotations.
#' @param geom name of geom to use for annotation
#' @param x,y,xmin,ymin,xmax,ymax,xend,yend positioning aesthetics -
Expand Down
2 changes: 1 addition & 1 deletion R/autolayer.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ autolayer <- function(object, ...) {

#' @export
autolayer.default <- function(object, ...) {
cli::cli_abort("No autolayer method available for {.cls {class(object)[1]}} objects")
cli::cli_abort("No autolayer method available for {.cls {class(object)[1]}} objects.")
}
2 changes: 1 addition & 1 deletion R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ autoplot <- function(object, ...) {
autoplot.default <- function(object, ...) {
cli::cli_abort(c(
"Objects of class {.cls {class(object)[[1]]}} are not supported by autoplot.",
"i" = "have you loaded the required package?"
"i" = "Have you loaded the required package?"
))
}

8 changes: 4 additions & 4 deletions R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ set_sec_axis <- function(sec.axis, scale) {
if (!is.waive(sec.axis)) {
if (is.formula(sec.axis)) sec.axis <- sec_axis(sec.axis)
if (!is.sec_axis(sec.axis)) {
cli::cli_abort("Secondary axes must be specified using {.fn sec_axis}")
cli::cli_abort("Secondary axes must be specified using {.fn sec_axis}.")
}
scale$secondary.axis <- sec.axis
}
Expand Down Expand Up @@ -165,7 +165,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
return()
}
if (!is.function(self$trans)) {
cli::cli_abort("Transformation for secondary axes must be a function")
cli::cli_abort("Transformation for secondary axes must be a function.")
}
if (is.derived(self$name) && !is.waive(scale$name)) self$name <- scale$name
if (is.derived(self$breaks)) self$breaks <- scale$breaks
Expand Down Expand Up @@ -194,7 +194,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,

# Test for monotonicity
if (!is_unique(sign(diff(full_range))))
cli::cli_abort("Transformation for secondary axes must be monotonic")
cli::cli_abort("Transformation for secondary axes must be monotonic.")
},

break_info = function(self, range, scale) {
Expand Down Expand Up @@ -280,7 +280,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
},

# Temporary scale for the purpose of calling break_info()
create_scale = function(self, range, trans = identity_trans()) {
create_scale = function(self, range, trans = transform_identity()) {
scale <- ggproto(NULL, ScaleContinuousPosition,
name = self$name,
breaks = self$breaks,
Expand Down
23 changes: 23 additions & 0 deletions R/backports.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,26 @@ if (getRversion() < "3.5") {
isFALSE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && !x
isTRUE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && x
}

version_unavailable <- function(...) {
fun <- as_label(current_call()[[1]])
cli::cli_abort("{.fn {fun}} is not available in R version {getRversion()}.")
}

# Ignore mask argument if on lower R version (<= 4.1)
viewport <- function(..., mask) grid::viewport(...)
pattern <- version_unavailable
as.mask <- version_unavailable
on_load({
if ("mask" %in% fn_fmls_names(grid::viewport)) {
viewport <- grid::viewport
}
# Replace version unavailable functions if found
if ("pattern" %in% getNamespaceExports("grid")) {
pattern <- grid::pattern
}
if ("as.mask" %in% getNamespaceExports("grid")) {
as.mask <- grid::as.mask
}
})

10 changes: 4 additions & 6 deletions R/bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ bin_breaks <- function(breaks, closed = c("right", "left")) {
bin_breaks_width <- function(x_range, width = NULL, center = NULL,
boundary = NULL, closed = c("right", "left")) {
if (length(x_range) != 2) {
cli::cli_abort("{.arg x_range} must have two elements")
cli::cli_abort("{.arg x_range} must have two elements.")
}

check_number_decimal(width)
if (width <= 0) {
cli::cli_abort("{.arg binwidth} must be positive")
}
# binwidth seems to be the argument name supplied to width. (stat-bin and stat-bindot)
check_number_decimal(width, min = 0, allow_infinite = FALSE, arg = "binwidth")

if (!is.null(boundary) && !is.null(center)) {
cli::cli_abort("Only one of {.arg boundary} and {.arg center} may be specified.")
Expand Down Expand Up @@ -105,7 +103,7 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
boundary = NULL, closed = c("right", "left")) {
if (length(x_range) != 2) {
cli::cli_abort("{.arg x_range} must have two elements")
cli::cli_abort("{.arg x_range} must have two elements.")
}

check_number_whole(bins, min = 1)
Expand Down
4 changes: 2 additions & 2 deletions R/compat-plyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ unrowname <- function(x) {
} else if (is.matrix(x)) {
dimnames(x)[1] <- list(NULL)
} else {
cli::cli_abort("Can only remove rownames from {.cls data.frame} and {.cls matrix} objects")
cli::cli_abort("Can only remove rownames from {.cls data.frame} and {.cls matrix} objects.")
}
x
}
Expand Down Expand Up @@ -239,7 +239,7 @@ as.quoted <- function(x, env = parent.frame()) {
} else if (is.call(x)) {
as.list(x)[-1]
} else {
cli::cli_abort("Must be a character vector, call, or formula")
cli::cli_abort("Must be a character vector, call, or formula.")
}
attributes(x) <- list(env = env, class = 'quoted')
x
Expand Down
10 changes: 5 additions & 5 deletions R/coord-.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ Coord <- ggproto("Coord",
render_fg = function(panel_params, theme) element_render(theme, "panel.border"),

render_bg = function(self, panel_params, theme) {
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_bg} method")
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_bg} method.")
},

render_axis_h = function(self, panel_params, theme) {
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_h} method")
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_h} method.")
},

render_axis_v = function(self, panel_params, theme) {
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_v} method")
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn render_axis_v} method.")
},

# transform range given in transformed coordinates
# back into range in given in (possibly scale-transformed)
# data coordinates
backtransform_range = function(self, panel_params) {
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn backtransform_range} method")
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn backtransform_range} method.")
},

# return range stored in panel_params
range = function(self, panel_params) {
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn range} method")
cli::cli_abort("{.fn {snake_class(self)}} has not implemented a {.fn range} method.")
},

setup_panel_params = function(scale_x, scale_y, params = list()) {
Expand Down
10 changes: 4 additions & 6 deletions R/coord-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
}

if (length(x_labels) != length(x_breaks)) {
cli::cli_abort("Breaks and labels along x direction are different lengths")
cli::cli_abort("{.arg breaks} and {.arg labels} along {.code x} direction have different lengths.")
}
graticule$degree_label[graticule$type == "E"] <- x_labels

Expand All @@ -152,7 +152,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
}

if (length(y_labels) != length(y_breaks)) {
cli::cli_abort("Breaks and labels along y direction are different lengths")
cli::cli_abort("{.arg breaks} and {.arg labels} along {.code y} direction have different lengths.")
}
graticule$degree_label[graticule$type == "N"] <- y_labels

Expand Down Expand Up @@ -203,7 +203,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
if (self$lims_method != "geometry_bbox") {
cli::cli_warn(c(
"Projection of {.field x} or {.field y} limits failed in {.fn coord_sf}.",
"i" = "Consider setting {.code lims_method = \"geometry_bbox\"} or {.code default_crs = NULL}."
"i" = "Consider setting {.code lims_method = {.val geometry_bbox}} or {.code default_crs = NULL}."
))
}
coord_bbox <- self$params$bbox
Expand Down Expand Up @@ -409,7 +409,7 @@ sf_rescale01 <- function(x, x_range, y_range) {
calc_limits_bbox <- function(method, xlim, ylim, crs, default_crs) {
if (any(!is.finite(c(xlim, ylim))) && method != "geometry_bbox") {
cli::cli_abort(c(
"Scale limits cannot be mapped onto spatial coordinates in {.fn coord_sf}",
"Scale limits cannot be mapped onto spatial coordinates in {.fn coord_sf}.",
"i" = "Consider setting {.code lims_method = \"geometry_bbox\"} or {.code default_crs = NULL}."
))
}
Expand Down Expand Up @@ -542,14 +542,12 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
label_axes <- parse_axes_labeling(label_axes)
} else if (!is.list(label_axes)) {
cli::cli_abort("Panel labeling format not recognized.")
label_axes <- list(left = "N", bottom = "E")
}

if (is.character(label_graticule)) {
label_graticule <- unlist(strsplit(label_graticule, ""))
} else {
cli::cli_abort("Graticule labeling format not recognized.")
label_graticule <- ""
}

# switch limit method to "orthogonal" if not specified and default_crs indicates projected coords
Expand Down
Loading

0 comments on commit 8863d83

Please sign in to comment.