Skip to content

Commit 74eb2b4

Browse files
alistaire47clauswilke
authored andcommitted
allow geom_sf to accept line parameters (#2826) (#2847)
Closes #2826 * fixed discrete_scale documentation Updated `discrete_scale` documentation to match functionality and `continuous_scale` (@alistaire47, $2052). * Cleaned up documentation inheritance * add line parameters to geom_sf #2826 * add line parameters to geom_sf (#2826) * refactor to add line parameters to sf_grob * updated NEWS.md for #2826 * Added Oxford comma
1 parent 5a37ae7 commit 74eb2b4

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 3.0.0.9000
22

3+
* `geom_sf()` now respects `lineend`, `linejoin`, and `linemitre` parameters
4+
for lines and polygons (@alistaire47, #2826)
5+
36
* `benchplot()` now uses tidy evaluation (@dpseidel, #2699).
47

58
* `fortify()` now displays a more informative error message for

R/sf.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,21 @@ GeomSf <- ggproto("GeomSf", Geom,
151151
stroke = 0.5
152152
),
153153

154-
draw_panel = function(data, panel_params, coord, legend = NULL) {
154+
draw_panel = function(data, panel_params, coord, legend = NULL,
155+
lineend = "butt", linejoin = "round", linemitre = 10) {
155156
if (!inherits(coord, "CoordSf")) {
156157
stop("geom_sf() must be used with coord_sf()", call. = FALSE)
157158
}
158159

159160
# Need to refactor this to generate one grob per geometry type
160161
coord <- coord$transform(data, panel_params)
161162
grobs <- lapply(1:nrow(data), function(i) {
162-
sf_grob(coord[i, , drop = FALSE])
163+
sf_grob(
164+
coord[i, , drop = FALSE],
165+
lineend = lineend,
166+
linejoin = linejoin,
167+
linemitre = linemitre
168+
)
163169
})
164170
do.call("gList", grobs)
165171
},
@@ -186,7 +192,7 @@ default_aesthetics <- function(type) {
186192
}
187193
}
188194

189-
sf_grob <- function(row) {
195+
sf_grob <- function(row, lineend, linejoin, linemitre) {
190196
# Need to extract geometry out of corresponding list column
191197
geometry <- row$geometry[[1]]
192198

@@ -207,7 +213,9 @@ sf_grob <- function(row) {
207213
fill = alpha(row$fill, row$alpha),
208214
lwd = row$size * .pt,
209215
lty = row$linetype,
210-
lineend = "butt"
216+
lineend = lineend,
217+
linejoin = linejoin,
218+
linemitre = linemitre
211219
)
212220
sf::st_as_grob(geometry, gp = gp)
213221
}

0 commit comments

Comments
 (0)