Skip to content

Commit c415307

Browse files
authored
Extent the range of geom_abline() outside the panel range (#4422)
1 parent 5274088 commit c415307

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

NEWS.md

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

3+
* Extent the range of the line created by `geom_abline()` so that line ending
4+
is not visible for large linewidths (@thomasp85, #4024)
35

46
* Make sure that default labels from default mappings doesn't overwrite default
57
labels from explicit mappings (@thomasp85, #2406)

R/geom-abline.r

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ GeomAbline <- ggproto("GeomAbline", Geom,
127127
draw_panel = function(data, panel_params, coord) {
128128
ranges <- coord$backtransform_range(panel_params)
129129

130+
if (coord$clip == "on" && coord$is_linear()) {
131+
# Ensure the line extends well outside the panel to avoid visible line
132+
# ending for thick lines
133+
ranges$x <- ranges$x + c(-1, 1) * diff(ranges$x)
134+
}
135+
130136
data$x <- ranges$x[1]
131137
data$xend <- ranges$x[2]
132138
data$y <- ranges$x[1] * data$slope + data$intercept

tests/figs/geom-hline-vline-abline/cartesian-lines-intersect-mid-bars.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/geom-hline-vline-abline/flipped-lines-intersect-mid-bars.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)