Skip to content

Commit 6704ea1

Browse files
authored
Consistent use of lineend and linejoin in geoms and keys (#4664)
1 parent aaaec2f commit 6704ea1

File tree

95 files changed

+1929
-1866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1929
-1866
lines changed

NEWS.md

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

3+
* All geoms now have consistent exposure of linejoin and lineend parameters, and
4+
the guide keys will now respect these settings (@thomasp85, #4653)
5+
36
* `geom_sf()` now respects `arrow` parameter for lines (@jakeruss, #4659)
47

58
* Updated documentation for `print.ggplot` to reflect that it returns

R/geom-abline.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ geom_abline <- function(mapping = NULL, data = NULL,
124124
#' @usage NULL
125125
#' @export
126126
GeomAbline <- ggproto("GeomAbline", Geom,
127-
draw_panel = function(data, panel_params, coord) {
127+
draw_panel = function(data, panel_params, coord, lineend = "butt") {
128128
ranges <- coord$backtransform_range(panel_params)
129129

130130
if (coord$clip == "on" && coord$is_linear()) {
@@ -138,7 +138,7 @@ GeomAbline <- ggproto("GeomAbline", Geom,
138138
data$y <- ranges$x[1] * data$slope + data$intercept
139139
data$yend <- ranges$x[2] * data$slope + data$intercept
140140

141-
GeomSegment$draw_panel(unique(data), panel_params, coord)
141+
GeomSegment$draw_panel(unique(data), panel_params, coord, lineend = lineend)
142142
},
143143

144144
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),

R/geom-bar.r

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,15 @@ GeomBar <- ggproto("GeomBar", GeomRect,
137137
flip_data(data, params$flipped_aes)
138138
},
139139

140-
draw_panel = function(self, data, panel_params, coord, width = NULL, flipped_aes = FALSE) {
140+
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
141+
linejoin = "mitre", width = NULL, flipped_aes = FALSE) {
141142
# Hack to ensure that width is detected as a parameter
142-
ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord)
143+
ggproto_parent(GeomRect, self)$draw_panel(
144+
data,
145+
panel_params,
146+
coord,
147+
lineend = lineend,
148+
linejoin = linejoin
149+
)
143150
}
144151
)

R/geom-boxplot.r

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
205205
flip_data(data, params$flipped_aes)
206206
},
207207

208-
draw_group = function(data, panel_params, coord, fatten = 2,
209-
outlier.colour = NULL, outlier.fill = NULL,
210-
outlier.shape = 19,
208+
draw_group = function(data, panel_params, coord, lineend = "butt",
209+
linejoin = "mitre", fatten = 2, outlier.colour = NULL,
210+
outlier.fill = NULL, outlier.shape = 19,
211211
outlier.size = 1.5, outlier.stroke = 0.5,
212-
outlier.alpha = NULL,
213-
notch = FALSE, notchwidth = 0.5, varwidth = FALSE, flipped_aes = FALSE) {
212+
outlier.alpha = NULL, notch = FALSE, notchwidth = 0.5,
213+
varwidth = FALSE, flipped_aes = FALSE) {
214214
data <- flip_data(data, flipped_aes)
215215
# this may occur when using geom_boxplot(stat = "identity")
216216
if (nrow(data) != 1) {
@@ -274,8 +274,16 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
274274

275275
ggname("geom_boxplot", grobTree(
276276
outliers_grob,
277-
GeomSegment$draw_panel(whiskers, panel_params, coord),
278-
GeomCrossbar$draw_panel(box, fatten = fatten, panel_params, coord, flipped_aes = flipped_aes)
277+
GeomSegment$draw_panel(whiskers, panel_params, coord, lineend = lineend),
278+
GeomCrossbar$draw_panel(
279+
box,
280+
fatten = fatten,
281+
panel_params,
282+
coord,
283+
lineend = lineend,
284+
linejoin = linejoin,
285+
flipped_aes = flipped_aes
286+
)
279287
))
280288
},
281289

R/geom-col.r

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ GeomCol <- ggproto("GeomCol", GeomRect,
5656
flip_data(data, params$flipped_aes)
5757
},
5858

59-
draw_panel = function(self, data, panel_params, coord, width = NULL, flipped_aes = FALSE) {
59+
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
60+
linejoin = "mitre", width = NULL, flipped_aes = FALSE) {
6061
# Hack to ensure that width is detected as a parameter
61-
ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord)
62+
ggproto_parent(GeomRect, self)$draw_panel(
63+
data,
64+
panel_params,
65+
coord,
66+
lineend = lineend,
67+
linejoin = linejoin
68+
)
6269
}
6370
)

R/geom-crossbar.r

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ GeomCrossbar <- ggproto("GeomCrossbar", Geom,
4747

4848
draw_key = draw_key_crossbar,
4949

50-
draw_panel = function(data, panel_params, coord, fatten = 2.5, width = NULL, flipped_aes = FALSE) {
50+
draw_panel = function(data, panel_params, coord, lineend = "butt",
51+
linejoin = "mitre", fatten = 2.5, width = NULL,
52+
flipped_aes = FALSE) {
5153
data <- flip_data(data, flipped_aes)
5254

5355
middle <- transform(data, x = xmin, xend = xmax, yend = y, size = size * fatten, alpha = NA)
@@ -99,8 +101,8 @@ GeomCrossbar <- ggproto("GeomCrossbar", Geom,
99101
middle <- flip_data(middle, flipped_aes)
100102

101103
ggname("geom_crossbar", gTree(children = gList(
102-
GeomPolygon$draw_panel(box, panel_params, coord),
103-
GeomSegment$draw_panel(middle, panel_params, coord)
104+
GeomPolygon$draw_panel(box, panel_params, coord, lineend = lineend, linejoin = linejoin),
105+
GeomSegment$draw_panel(middle, panel_params, coord, lineend = lineend, linejoin = linejoin)
104106
)))
105107
}
106108
)

R/geom-dotplot.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
264264
},
265265

266266

267-
draw_group = function(data, panel_params, coord, na.rm = FALSE,
267+
draw_group = function(data, panel_params, coord, lineend = "butt", na.rm = FALSE,
268268
binaxis = "x", stackdir = "up", stackratio = 1,
269269
dotsize = 1, stackgroups = FALSE) {
270270
if (!coord$is_linear()) {
@@ -292,7 +292,8 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
292292
default.units = "npc",
293293
gp = gpar(col = alpha(tdata$colour, tdata$alpha),
294294
fill = alpha(tdata$fill, tdata$alpha),
295-
lwd = tdata$stroke, lty = tdata$linetype))
295+
lwd = tdata$stroke, lty = tdata$linetype,
296+
lineend = lineend))
296297
)
297298
},
298299

R/geom-errorbar.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
5252
flip_data(data, params$flipped_aes)
5353
},
5454

55-
draw_panel = function(data, panel_params, coord, width = NULL, flipped_aes = FALSE) {
55+
draw_panel = function(data, panel_params, coord, lineend = "butt", width = NULL, flipped_aes = FALSE) {
5656
data <- flip_data(data, flipped_aes)
5757
x <- as.vector(rbind(data$xmin, data$xmax, NA, data$x, data$x, NA, data$xmin, data$xmax))
5858
y <- as.vector(rbind(data$ymax, data$ymax, NA, data$ymax, data$ymin, NA, data$ymin, data$ymin))
@@ -67,6 +67,6 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
6767
row.names = 1:(nrow(data) * 8)
6868
))
6969
data <- flip_data(data, flipped_aes)
70-
GeomPath$draw_panel(data, panel_params, coord)
70+
GeomPath$draw_panel(data, panel_params, coord, lineend = lineend)
7171
}
7272
)

R/geom-errorbarh.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ GeomErrorbarh <- ggproto("GeomErrorbarh", Geom,
6767
)
6868
},
6969

70-
draw_panel = function(data, panel_params, coord, height = NULL) {
70+
draw_panel = function(data, panel_params, coord, height = NULL, lineend = "butt") {
7171
GeomPath$draw_panel(new_data_frame(list(
7272
x = as.vector(rbind(data$xmax, data$xmax, NA, data$xmax, data$xmin, NA, data$xmin, data$xmin)),
7373
y = as.vector(rbind(data$ymin, data$ymax, NA, data$y, data$y, NA, data$ymin, data$ymax)),
@@ -77,6 +77,6 @@ GeomErrorbarh <- ggproto("GeomErrorbarh", Geom,
7777
linetype = rep(data$linetype, each = 8),
7878
group = rep(1:(nrow(data)), each = 8),
7979
row.names = 1:(nrow(data) * 8)
80-
)), panel_params, coord)
80+
)), panel_params, coord, lineend = lineend)
8181
}
8282
)

R/geom-hex.r

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ geom_hex <- function(mapping = NULL, data = NULL,
5454
#' @usage NULL
5555
#' @export
5656
GeomHex <- ggproto("GeomHex", Geom,
57-
draw_group = function(data, panel_params, coord) {
57+
draw_group = function(data, panel_params, coord, lineend = "butt",
58+
linejoin = "mitre", linemitre = 10) {
5859
if (!inherits(coord, "CoordCartesian")) {
5960
abort("geom_hex() only works with Cartesian coordinates")
6061
}
@@ -66,7 +67,10 @@ GeomHex <- ggproto("GeomHex", Geom,
6667
col = coords$colour,
6768
fill = alpha(coords$fill, coords$alpha),
6869
lwd = coords$size * .pt,
69-
lty = coords$linetype
70+
lty = coords$linetype,
71+
lineend = lineend,
72+
linejoin = linejoin,
73+
linemitre = linemitre
7074
)
7175
))
7276
},

0 commit comments

Comments
 (0)