Skip to content

Commit 252e3c0

Browse files
authored
Stack divide zero (#6341)
* avoid dividing by zero * add news bullet
1 parent 4eaa98b commit 252e3c0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ggplot2 (development version)
22

3+
* `position_fill()` avoids stacking observations of zero (@teunbrand, #6338)
34
* New `layer(layout)` argument to interact with facets (@teunbrand, #3062)
45
* New `stat_connect()` to connect points via steps or other shapes
56
(@teunbrand, #6228)

R/position-stack.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ pos_stack <- function(df, width, vjust = 1, fill = FALSE) {
224224
heights <- c(0, cumsum(y))
225225

226226
if (fill) {
227-
heights <- heights / abs(heights[length(heights)])
227+
total <- abs(heights[length(heights)])
228+
if (total > sqrt(.Machine$double.eps)) {
229+
heights <- heights / total
230+
}
228231
}
229232
# We need to preserve ymin/ymax order. If ymax is lower than ymin in input, it should remain that way
230233
if (!is.null(df$ymin) && !is.null(df$ymax)) {

0 commit comments

Comments
 (0)