Skip to content

Commit cd16455

Browse files
authored
Merge pull request #1481 from ropensci/sf-fix
Fixes for ggplot2 >3.1.0
2 parents 34c51b3 + 37b79e9 commit cd16455

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

R/ggplotly.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,18 @@ gg2list <- function(p, width = NULL, height = NULL,
236236
out
237237
}
238238

239+
# ggplot2 3.1.0.9000 introduced a Layer method named setup_layer()
240+
# currently, LayerSf is the only core-ggplot2 Layer that makes use
241+
# of it https://github.com/tidyverse/ggplot2/pull/2875
242+
data <- layer_data
243+
if (packageVersion("ggplot2") > "3.1.0") {
244+
data <- by_layer(function(l, d) l$setup_layer(d, plot))
245+
}
246+
239247
# Initialise panels, add extra data for margins & missing facetting
240248
# variables, and add on a PANEL variable to data
241249
layout <- ggfun("create_layout")(plot$facet, plot$coordinates)
242-
data <- layout$setup(layer_data, plot$data, plot$plot_env)
250+
data <- layout$setup(data, plot$data, plot$plot_env)
243251

244252
# save the domain of the group for display in tooltips
245253
groupDomains <- Map(function(x, y) {

R/layers2traces.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,12 @@ aes2plotly <- function(data, params, aes = "size") {
10001000
type <- if (any(grepl("point", class(data)))) "point" else if (any(grepl("line", class(data)))) "line" else ""
10011001
ggfun("default_aesthetics")(type)
10021002
} else {
1003-
ggfun(geom)$default_aes
1003+
geom_obj <- ggfun(geom)
1004+
# If the first class of `data` is a data.frame,
1005+
# ggfun() returns a function because ggplot2 now
1006+
# defines data.frame in it's namespace
1007+
# https://github.com/ropensci/plotly/pull/1481
1008+
if ("default_aes" %in% names(geom_obj)) geom_obj$default_aes else NULL
10041009
}
10051010

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

0 commit comments

Comments
 (0)