@@ -14,20 +14,17 @@ layer_sf <- function(geom = NULL, stat = NULL,
14
14
inherit.aes = TRUE , check.aes = TRUE , check.param = TRUE ,
15
15
show.legend = NA ) {
16
16
if (is.character(show.legend )) {
17
- legend_key_type <- show.legend
17
+ params $ legend <- show.legend
18
18
show.legend <- TRUE
19
19
} else {
20
- legend_key_type <- NULL
20
+ params $ legend <- NULL
21
21
}
22
22
23
- # inherit from LayerSf class to add `legend_key_type` slot
24
- layer_class <- ggproto(NULL , LayerSf , legend_key_type = legend_key_type )
25
-
26
23
layer(
27
24
geom = geom , stat = stat , data = data , mapping = mapping ,
28
25
position = position , params = params , inherit.aes = inherit.aes ,
29
26
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
31
28
)
32
29
}
33
30
@@ -47,19 +44,15 @@ LayerSf <- ggproto("LayerSf", Layer,
47
44
}
48
45
49
46
# 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"
60
55
}
61
- } else {
62
- self $ geom_params $ legend <- self $ legend_key_type
63
56
}
64
57
data
65
58
}
0 commit comments