Skip to content

Updates in support of ggplot2 v4.0.0 #2442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
plotly_api_key: ${{ secrets.PLOTLY_API_KEY }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
persist-credentials: false

Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ RoxygenNote: 7.3.2
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Config/Needs/check:
tidyverse/ggplot2,
rcmdcheck,
devtools,
reshape2,
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Improvements

* `ggplotly()` now works better with the development version of ggplot2 (> v3.4.4). (#2315, #2368)
* Various updates to `ggplotly()` to better support recent versions of ggplot2. (#2315, #2368, #2442, thanks @teunbrand).

## Bug fixes

Expand Down
19 changes: 13 additions & 6 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,9 @@ gg2list <- function(p, width = NULL, height = NULL,
"\\*\\s+degree[ ]?[\\*]?", "&#176;",
gsub("\"", "", tickData[["degree_label"]])
)
rng[[paste0(xy, ".major")]] <- tickData[[paste0(xy, "_start")]]
# Downstream logic expects these 'break positions' to be on 0-1 scale
# (which is then rescaled back to the data scale)
rng[[paste0(xy, ".major")]] <- scales::rescale(tickData[[paste0(xy, "_start")]])

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

# https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809
hasTickText <- !(is.na(ticktext) | is.na(tickvals))
ticktext <- ticktext[hasTickText]
tickvals <- tickvals[hasTickText]
ticktext <- as.character(unlist(ticktext[hasTickText]))
tickvals <- as.numeric(unlist(tickvals[hasTickText]))

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

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

list(
Expand Down
1 change: 1 addition & 0 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ to_basic.GeomCol <- function(data, prestats_data, layout, params, p, ...) {
#' @export
to_basic.GeomViolin <- function(data, prestats_data, layout, params, p, ...) {
n <- nrow(data)
data <- data[order(data[["y"]], decreasing = FALSE), ]
revData <- data[order(data[["y"]], decreasing = TRUE), ]
idx <- !names(data) %in% c("x", "xmin", "xmax")
data <- rbind(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggalluvial/stratum-alluvium.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-col/col.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-contour/contour.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-facets/3-panels.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-facets/barley.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-heatmap/tile-no-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-histogram/histogram-dates.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-histogram/histogram-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-histogram/histogram-vline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-labels/labs-element-blank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-map/map-facet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-sf/sf-aspect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-sf/sf-axis-ticks.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-sf/sf-fill-text.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-sf/sf-geom-collection.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-sf/sf-points.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-sf/sf-theme-map.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-sf/sf.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-text/text-colour.svg

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-ticks/ticks-uneven.svg

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggplot-violin/violin.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ggridges/histogram-ridges.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/mean-error-bars/error-rect-alpha.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/plotly-subplot/ggally-ggcorr.svg

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/test-ggplot-labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ test_that("empty labels work", {
p <- ggplot(palmerpenguins::penguins,
aes(bill_length_mm, bill_depth_mm, color = species)) +
geom_point() +
labs(x = element_blank(), y = element_blank())
labs(x = NULL, y = NULL)
b <- expect_doppelganger_built(p, "labs-element-blank")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-ggplot-ticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ test_that("Set the X tick mark locations", {
test_that("The breaks can be spaced unevenly", {
boxes.uneven <- boxes +
scale_y_continuous(breaks = c(4, 4.25, 4.5, 5, 6, 8))
info <- expect_traces(no.breaks, 1, "uneven")
info <- expect_traces(boxes.uneven, 1, "uneven")
})

test_that("R line breaks are translated to HTML line breaks", {
Expand Down