Skip to content

Commit dcad61a

Browse files
Handle when geometry is not a symbol (#4127)
Fix #4122 * Handle when `geometry` is not a symbol * Fix a comment
1 parent a11e098 commit dcad61a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

R/layer-sf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LayerSf <- ggproto("LayerSf", Layer,
5252
self$geom_params$legend <- "polygon"
5353

5454
# now check if the type should not be polygon
55-
if (!is.null(self$mapping$geometry)) {
55+
if (!is.null(self$mapping$geometry) && quo_is_symbol(self$mapping$geometry)) {
5656
geometry_column <- as_name(self$mapping$geometry)
5757
if (inherits(data[[geometry_column]], "sfc")) {
5858
sf_type <- detect_sf_type(data[[geometry_column]])

tests/testthat/test-geom-sf.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ test_that("geom_sf() determines the legend type from mapped geometry column", {
7676
ggplot(d_sf) + geom_sf(aes(geometry = g_line, colour = "a"))
7777
)
7878
expect_identical(p$plot$layers[[1]]$geom_params$legend, "line")
79+
80+
# If `geometry` is not a symbol, `LayerSf$setup_layer()` gives up guessing
81+
# the legend type, and falls back to "polygon"
82+
p <- ggplot_build(
83+
ggplot(d_sf) + geom_sf(aes(geometry = identity(g_point), colour = "a"))
84+
)
85+
expect_identical(p$plot$layers[[1]]$geom_params$legend, "polygon")
7986
})
8087

8188
test_that("geom_sf() removes rows containing missing aes", {

0 commit comments

Comments
 (0)