Skip to content

Fixes for ggplot2 >3.1.0 #1481

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 3 commits into from
Mar 11, 2019
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
10 changes: 9 additions & 1 deletion R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,18 @@ gg2list <- function(p, width = NULL, height = NULL,
out
}

# ggplot2 3.1.0.9000 introduced a Layer method named setup_layer()
# currently, LayerSf is the only core-ggplot2 Layer that makes use
# of it https://github.com/tidyverse/ggplot2/pull/2875
data <- layer_data
if (packageVersion("ggplot2") > "3.1.0") {
data <- by_layer(function(l, d) l$setup_layer(d, plot))
}

# Initialise panels, add extra data for margins & missing facetting
# variables, and add on a PANEL variable to data
layout <- ggfun("create_layout")(plot$facet, plot$coordinates)
data <- layout$setup(layer_data, plot$data, plot$plot_env)
data <- layout$setup(data, plot$data, plot$plot_env)

# save the domain of the group for display in tooltips
groupDomains <- Map(function(x, y) {
Expand Down
7 changes: 6 additions & 1 deletion R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,12 @@ aes2plotly <- function(data, params, aes = "size") {
type <- if (any(grepl("point", class(data)))) "point" else if (any(grepl("line", class(data)))) "line" else ""
ggfun("default_aesthetics")(type)
} else {
ggfun(geom)$default_aes
geom_obj <- ggfun(geom)
# If the first class of `data` is a data.frame,
# ggfun() returns a function because ggplot2 now
# defines data.frame in it's namespace
# https://github.com/ropensci/plotly/pull/1481
if ("default_aes" %in% names(geom_obj)) geom_obj$default_aes else NULL
}

vals <- uniq(data[[aes]]) %||% params[[aes]] %||% defaults[[aes]] %||% NA
Expand Down