Skip to content

Commit 7a0176d

Browse files
cpsievertCopilot
andauthored
Updates in support of ggplot2 v4.0.0 (#2442)
* Run tests against dev ggplot2 * Take changes from #2440 * Approve (a subset of) new snapshots * Ensure ticktext/tickvals is atomic character/numeric vector * Fix geom_sf() break positions * Fix for geom_violin() * Update news * Approve good visual changes * Approve more visual changes; fix test expectation * Accept new snapshot * Zero length ticktext/tickvals should remain NULL * Zero length vs NULL can actually be meaningful so just safe guard against error * Approve new snapshot * Refactor * Update NEWS.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 3b5f6e6 commit 7a0176d

Some content is hidden

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

48 files changed

+60
-51
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
plotly_api_key: ${{ secrets.PLOTLY_API_KEY }}
4747

4848
steps:
49-
- uses: actions/checkout@v2
49+
- uses: actions/checkout@v4
5050
with:
5151
persist-credentials: false
5252

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ RoxygenNote: 7.3.2
8282
Encoding: UTF-8
8383
Roxygen: list(markdown = TRUE)
8484
Config/Needs/check:
85+
tidyverse/ggplot2,
8586
rcmdcheck,
8687
devtools,
8788
reshape2,

NEWS.md

Lines changed: 1 addition & 1 deletion

R/ggplotly.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,9 @@ gg2list <- function(p, width = NULL, height = NULL,
668668
"\\*\\s+degree[ ]?[\\*]?", "&#176;",
669669
gsub("\"", "", tickData[["degree_label"]])
670670
)
671-
rng[[paste0(xy, ".major")]] <- tickData[[paste0(xy, "_start")]]
671+
# Downstream logic expects these 'break positions' to be on 0-1 scale
672+
# (which is then rescaled back to the data scale)
673+
rng[[paste0(xy, ".major")]] <- scales::rescale(tickData[[paste0(xy, "_start")]])
672674

673675
# If it doesn't already exist (for this panel),
674676
# generate graticule (as done in, CoordSf$render_bg)
@@ -742,8 +744,8 @@ gg2list <- function(p, width = NULL, height = NULL,
742744

743745
# https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809
744746
hasTickText <- !(is.na(ticktext) | is.na(tickvals))
745-
ticktext <- ticktext[hasTickText]
746-
tickvals <- tickvals[hasTickText]
747+
ticktext <- as.character(unlist(ticktext[hasTickText]))
748+
tickvals <- as.numeric(unlist(tickvals[hasTickText]))
747749

748750
axisObj <- list(
749751
# TODO: log type?
@@ -783,8 +785,11 @@ gg2list <- function(p, width = NULL, height = NULL,
783785
# set scaleanchor/scaleratio if these are fixed coordinates
784786
# the logic here is similar to what p$coordinates$aspect() does,
785787
# but the ratio is scaled to the data range by plotly.js
786-
fixed_coords <- c("CoordSf", "CoordFixed", "CoordMap", "CoordQuickmap")
787-
if (inherits(p$coordinates, fixed_coords)) {
788+
is_fixed <- inherits(
789+
p$coordinates,
790+
c("CoordSf", "CoordFixed", "CoordMap", "CoordQuickmap")
791+
)
792+
if (is_fixed || isFALSE(p$coordinates$is_free())) {
788793
axisObj$scaleanchor <- anchor
789794
ratio <- p$coordinates$ratio %||% 1
790795
axisObj$scaleratio <- if (xy == "y") ratio else 1 / ratio
@@ -1436,7 +1441,9 @@ gdef2trace <- function(gdef, theme, gglayout) {
14361441
}
14371442

14381443
vals <- lapply(gglayout[c("xaxis", "yaxis")], function(ax) {
1439-
if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
1444+
res <- if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
1445+
# if zero-length, return NULL to avoid subscript oob errors
1446+
res %||% NULL
14401447
})
14411448

14421449
list(

R/layers2traces.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ to_basic.GeomCol <- function(data, prestats_data, layout, params, p, ...) {
197197
#' @export
198198
to_basic.GeomViolin <- function(data, prestats_data, layout, params, p, ...) {
199199
n <- nrow(data)
200+
data <- data[order(data[["y"]], decreasing = FALSE), ]
200201
revData <- data[order(data[["y"]], decreasing = TRUE), ]
201202
idx <- !names(data) %in% c("x", "xmin", "xmax")
202203
data <- rbind(

tests/testthat/_snaps/cookbook-axes/cookbook-axes-log2-labels.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggalluvial/stratum-alluvium-color.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg

Lines changed: 1 addition & 1 deletion

tests/testthat/_snaps/ggplot-col/col.svg

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)