Skip to content

Commit

Permalink
fixes for ggplot2 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Feb 23, 2024
1 parent d79fbd3 commit 1dfa576
Show file tree
Hide file tree
Showing 93 changed files with 979 additions and 699 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Description: Provides primitives for visualizing distributions using 'ggplot2' t
Depends:
R (>= 3.6.0)
Imports:
ggplot2 (>= 3.4.0),
ggplot2 (>= 3.5.0),
rlang (>= 0.3.0),
cli,
scales,
Expand Down
5 changes: 3 additions & 2 deletions R/binning_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ find_dotplot_binwidth = function(
layout = c("bin", "weave", "hex", "swarm", "bar")
) {
layout = match.arg(layout)
x = sort(x, na.last = TRUE)
x = sort(as.numeric(x), na.last = TRUE)

# figure out a reasonable minimum number of bins based on histogram binning
min_nbins = if (length(x) <= 1) {
Expand Down Expand Up @@ -633,7 +633,8 @@ select_bin_method = function(x, layout = "bin") {
#' @noRd
bar_bin = function(x, width, bar_scale = 0.9) {
# determine the amount of space that each bar will take up
max_bar_width = resolution(x, zero = FALSE) * bar_scale
# TODO: can drop as.numeric here if https://github.com/tidyverse/ggplot2/issues/5709 is fixed
max_bar_width = resolution(as.numeric(x), zero = FALSE) * bar_scale
n_bins = max(floor(max_bar_width / width), 1)
actual_bar_width = n_bins * width

Expand Down
3 changes: 2 additions & 1 deletion R/geom_slabinterval.R
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ GeomSlabinterval = ggproto("GeomSlabinterval", AbstractGeom,
# this is necessary so that the bounding box is correct for
# positions to work (e.g. position_dodge, etc)
data[[height]] = params[[height]] %||% data[[height]] %||%
resolution(data[[y]], FALSE)
# TODO: can drop as.numeric here if https://github.com/tidyverse/ggplot2/issues/5709 is fixed
resolution(as.numeric(data[[y]]), FALSE)

# determine bounding boxes based on justification: position
# the min/max bounds around y such that y is at the correct
Expand Down
22 changes: 18 additions & 4 deletions R/guide_rampbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,24 @@ guide_rampbar = function(..., to = "gray65", available_aes = c("fill_ramp", "col
new_guide = ggproto(
"GuideRampbar", guide,
params = c(list(to = to), guide$params),
extract_decor = function(scale, aesthetic, nbin = 300,
reverse = FALSE, to = "gray65", ...) {
bar = guide$extract_decor(scale, aesthetic, nbin, reverse, ...)
bar$colour = apply_colour_ramp(to, bar$colour)
extract_decor = function(
scale, aesthetic, nbin = 300, reverse = FALSE, alpha = NA,
to = "gray65", ...
) {
limits <- scale$get_limits()
bar <- seq(limits[1], limits[2], length.out = nbin)
if (length(bar) == 0) {
bar <- unique(limits)
}
bar <- data_frame(
colour = scale$map(bar),
value = bar,
.size = length(bar)
)
if (reverse) {
bar <- bar[nrow(bar):1, , drop = FALSE]
}
bar$colour = alpha(apply_colour_ramp(to, bar$colour), alpha)
bar
}
)
Expand Down
34 changes: 17 additions & 17 deletions R/scale_.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,26 @@ scale_point_fill_continuous = function(..., aesthetics = "point_fill", guide = g
#' @importFrom scales rescale_pal
#' @export
scale_point_alpha_continuous = function(..., range = c(0.1, 1)) {
continuous_scale("point_alpha", "point_alpha_c", rescale_pal(range), ...)
continuous_scale("point_alpha", palette = rescale_pal(range), ...)
}
#' @rdname scales
#' @export
scale_point_alpha_discrete = function(..., range = c(0.1, 1)) {
discrete_scale("point_alpha", "point_alpha_d", function(n) seq(range[1], range[2], length.out = n), ...)
discrete_scale("point_alpha", palette = function(n) seq(range[1], range[2], length.out = n), ...)
}


#' @rdname scales
#' @importFrom scales area_pal
#' @export
scale_point_size_continuous =
function(..., range = c(1, 6)) continuous_scale("point_size", "point_size_c", area_pal(range), ...)
function(..., range = c(1, 6)) continuous_scale("point_size", palette = area_pal(range), ...)
#' @rdname scales
#' @export
scale_point_size_discrete = function(..., range = c(1, 6), na.translate = FALSE) {
force(range)
discrete_scale(
"point_size", "point_size_d", function(n) seq(range[1], range[2], length.out = n),
"point_size", palette = function(n) seq(range[1], range[2], length.out = n),
na.translate = na.translate, ...
)
}
Expand Down Expand Up @@ -180,26 +180,26 @@ scale_interval_color_continuous = scale_interval_colour_continuous
#' @importFrom scales rescale_pal
#' @export
scale_interval_alpha_continuous = function(..., range = c(0.1, 1)) {
continuous_scale("interval_alpha", "interval_alpha_c", rescale_pal(range), ...)
continuous_scale("interval_alpha", palette = rescale_pal(range), ...)
}
#' @rdname scales
#' @export
scale_interval_alpha_discrete = function(..., range = c(0.1, 1)) {
discrete_scale("interval_alpha", "interval_alpha_d", function(n) seq(range[1], range[2], length.out = n), ...)
discrete_scale("interval_alpha", palette = function(n) seq(range[1], range[2], length.out = n), ...)
}


#' @rdname scales
#' @importFrom scales area_pal
#' @export
scale_interval_size_continuous =
function(..., range = c(1, 6)) continuous_scale("interval_size", "interval_size_c", area_pal(range), ...)
function(..., range = c(1, 6)) continuous_scale("interval_size", palette = area_pal(range), ...)
#' @rdname scales
#' @export
scale_interval_size_discrete = function(..., range = c(1, 6), na.translate = FALSE) {
force(range)
discrete_scale(
"interval_size", "interval_size_d", function(n) seq(range[1], range[2], length.out = n),
"interval_size", palette = function(n) seq(range[1], range[2], length.out = n),
na.translate = na.translate, ...
)
}
Expand All @@ -209,7 +209,7 @@ scale_interval_size_discrete = function(..., range = c(1, 6), na.translate = FAL
#' @importFrom scales linetype_pal
#' @export
scale_interval_linetype_discrete = function(..., na.value = "blank") {
discrete_scale("interval_linetype", "interval_linetype_d", linetype_pal(), na.value = na.value, ...)
discrete_scale("interval_linetype", palette = linetype_pal(), na.value = na.value, ...)
}
#' @rdname scales
#' @export
Expand Down Expand Up @@ -252,26 +252,26 @@ scale_slab_fill_continuous = function(..., aesthetics = "slab_fill", guide = gui
#' @importFrom scales rescale_pal
#' @export
scale_slab_alpha_continuous = function(..., limits = function(l) c(min(0, l[[1]]), l[[2]]), range = c(0, 1)) {
continuous_scale("slab_alpha", "slab_alpha_c", rescale_pal(range), limits = limits, ...)
continuous_scale("slab_alpha", palette = rescale_pal(range), limits = limits, ...)
}
#' @rdname scales
#' @export
scale_slab_alpha_discrete = function(..., range = c(0.1, 1)) {
discrete_scale("slab_alpha", "slab_alpha_d", function(n) seq(range[1], range[2], length.out = n), ...)
discrete_scale("slab_alpha", palette = function(n) seq(range[1], range[2], length.out = n), ...)
}


#' @rdname scales
#' @importFrom scales rescale_pal
#' @export
scale_slab_size_continuous =
function(..., range = c(1, 6)) continuous_scale("slab_size", "slab_size_c", rescale_pal(range), ...)
function(..., range = c(1, 6)) continuous_scale("slab_size", palette = rescale_pal(range), ...)
#' @rdname scales
#' @export
scale_slab_size_discrete = function(..., range = c(1, 6), na.translate = FALSE) {
force(range)
discrete_scale(
"slab_size", "slab_size_d", function(n) seq(range[1], range[2], length.out = n),
"slab_size", palette = function(n) seq(range[1], range[2], length.out = n),
na.translate = na.translate, ...
)
}
Expand All @@ -281,13 +281,13 @@ scale_slab_size_discrete = function(..., range = c(1, 6), na.translate = FALSE)
#' @importFrom scales rescale_pal
#' @export
scale_slab_linewidth_continuous =
function(..., range = c(1, 6)) continuous_scale("slab_linewidth", "slab_linewidth_c", rescale_pal(range), ...)
function(..., range = c(1, 6)) continuous_scale("slab_linewidth", palette = rescale_pal(range), ...)
#' @rdname scales
#' @export
scale_slab_linewidth_discrete = function(..., range = c(1, 6), na.translate = FALSE) {
force(range)
discrete_scale(
"slab_linewidth", "slab_linewidth_d", function(n) seq(range[1], range[2], length.out = n),
"slab_linewidth", palette = function(n) seq(range[1], range[2], length.out = n),
na.translate = na.translate, ...
)
}
Expand All @@ -297,7 +297,7 @@ scale_slab_linewidth_discrete = function(..., range = c(1, 6), na.translate = FA
#' @importFrom scales linetype_pal
#' @export
scale_slab_linetype_discrete = function(..., na.value = "blank") {
discrete_scale("slab_linetype", "slab_linetype_d", linetype_pal(), na.value = na.value, ...)
discrete_scale("slab_linetype", palette = linetype_pal(), na.value = na.value, ...)
}
#' @rdname scales
#' @export
Expand All @@ -310,7 +310,7 @@ scale_slab_linetype_continuous = function(...) {
#' @importFrom scales shape_pal
#' @export
scale_slab_shape_discrete = function(..., solid = TRUE) {
discrete_scale("slab_shape", "slab_shape_d", shape_pal(solid), ...)
discrete_scale("slab_shape", palette = shape_pal(solid), ...)
}
#' @rdname scales
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/scale_colour_ramp.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ scale_colour_ramp_continuous = function(
) {
scale = ggproto(NULL, ScaleColourRampContinuous, from = from)
continuous_scale(
aesthetics, "colour_ramp_c", rescale_pal(range), limits = limits, guide = guide, ..., super = scale
aesthetics, palette = rescale_pal(range), limits = limits, guide = guide, ..., super = scale
)
}
#' @rdname scale_colour_ramp
Expand All @@ -86,7 +86,7 @@ scale_colour_ramp_discrete = function(
) {
scale = ggproto(NULL, ScaleColourRampDiscrete, from = from)
discrete_scale(
aesthetics, "colour_ramp_d", function(n) seq(range[1], range[2], length.out = n), ..., super = scale
aesthetics, palette = function(n) seq(range[1], range[2], length.out = n), ..., super = scale
)
}
#' @rdname scale_colour_ramp
Expand Down
2 changes: 1 addition & 1 deletion R/scale_side_mirrored.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ scale_side_mirrored = function(
start = "topright", ..., aesthetics = "side"
) {
discrete_scale(
aesthetics, "side_d", side_mirrored_pal(start), ...
aesthetics, palette = side_mirrored_pal(start), ...
)
}

Expand Down
4 changes: 2 additions & 2 deletions R/scale_thickness.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ scale_thickness_shared = function(
...
) {
sc = continuous_scale(
"thickness", "thickness_c", identity_pal(),
"thickness", palette = identity_pal(),
name = name, breaks = breaks, labels = labels,
limits = limits,
oob = oob,
Expand Down Expand Up @@ -149,7 +149,7 @@ ScaleThicknessShared = ggproto("ScaleThicknessShared", ScaleContinuous,
#' @export
scale_thickness_identity = function(..., guide = "none") {
continuous_scale(
"thickness", "identity", identity_pal(),
"thickness", palette = identity_pal(),
...,
guide = guide, super = ScaleContinuousIdentity
)
Expand Down
6 changes: 4 additions & 2 deletions R/smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ smooth_discrete = auto_partial(name = "smooth_discrete", function(
cosine = 0.18,
optcosine = 0.20
)
bandwidth = resolution(x, zero = FALSE) * bw_mult * width
# TODO: can drop as.numeric here if https://github.com/tidyverse/ggplot2/issues/5709 is fixed
bandwidth = resolution(as.numeric(x), zero = FALSE) * bw_mult * width
smooth_unbounded(x, kernel = kernel, bandwidth = bandwidth, ...)
})

Expand All @@ -228,7 +229,8 @@ smooth_discrete = auto_partial(name = "smooth_discrete", function(
smooth_bar = auto_partial(name = "smooth_bar", function(x, width = 0.7, ...) {
if (length(x) < 2) return(x)

x_width = resolution(x, zero = FALSE) * width
# TODO: can drop as.numeric here if https://github.com/tidyverse/ggplot2/issues/5709 is fixed
x_width = resolution(as.numeric(x), zero = FALSE) * width
split(x, x) = lapply(split(x, x), function(x) {
(ppoints(length(x), 0.5) - 0.5) * x_width + x[[1]]
})
Expand Down
67 changes: 21 additions & 46 deletions man/guide_rampbar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/scale_side_mirrored.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1dfa576

Please sign in to comment.