Skip to content

Commit 2b6317d

Browse files
Use geom_params$legend instead of a new parameter
1 parent 89a5044 commit 2b6317d

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

R/layer-sf.R

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@ layer_sf <- function(geom = NULL, stat = NULL,
1414
inherit.aes = TRUE, check.aes = TRUE, check.param = TRUE,
1515
show.legend = NA) {
1616
if (is.character(show.legend)) {
17-
legend_key_type <- show.legend
17+
params$legend <- show.legend
1818
show.legend <- TRUE
1919
} else {
20-
legend_key_type <- NULL
20+
params$legend <- NULL
2121
}
2222

23-
# inherit from LayerSf class to add `legend_key_type` slot
24-
layer_class <- ggproto(NULL, LayerSf, legend_key_type = legend_key_type)
25-
2623
layer(
2724
geom = geom, stat = stat, data = data, mapping = mapping,
2825
position = position, params = params, inherit.aes = inherit.aes,
2926
check.aes = check.aes, check.param = check.param,
30-
show.legend = show.legend, layer_class = layer_class
27+
show.legend = show.legend, layer_class = LayerSf
3128
)
3229
}
3330

@@ -47,19 +44,15 @@ LayerSf <- ggproto("LayerSf", Layer,
4744
}
4845

4946
# automatically determine the legend type
50-
if (is.null(self$legend_key_type)) {
51-
if (is_sf(data)) {
52-
sf_type <- detect_sf_type(data)
53-
if (sf_type == "point") {
54-
self$geom_params$legend <- "point"
55-
} else if (sf_type == "line") {
56-
self$geom_params$legend <- "line"
57-
} else {
58-
self$geom_params$legend <- "polygon"
59-
}
47+
if (is.null(self$geom_params$legend) && is_sf(data)) {
48+
sf_type <- detect_sf_type(data)
49+
if (sf_type == "point") {
50+
self$geom_params$legend <- "point"
51+
} else if (sf_type == "line") {
52+
self$geom_params$legend <- "line"
53+
} else {
54+
self$geom_params$legend <- "polygon"
6055
}
61-
} else {
62-
self$geom_params$legend <- self$legend_key_type
6356
}
6457
data
6558
}

0 commit comments

Comments
 (0)