Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* `stat_count()` now computes width based on the full dataset instead of per
group (@thomasp85, #2047)

* Fix bug in `labeller()` where parsing was turned off if `.multiline = FALSE`
(@thomasp85, #4084)
Expand Down
6 changes: 5 additions & 1 deletion R/stat-count.r
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ StatCount <- ggproto("StatCount", Stat,
abort("stat_count() can only have an x or y aesthetic.")
}

if (is.null(params$width)) {
x <- if (params$flipped_aes) "y" else "x"
params$width <- resolution(data[[x]]) * 0.9
}

params
},

Expand All @@ -73,7 +78,6 @@ StatCount <- ggproto("StatCount", Stat,
data <- flip_data(data, flipped_aes)
x <- data$x
weight <- data$weight %||% rep(1, length(x))
width <- width %||% (resolution(x) * 0.9)

count <- as.numeric(tapply(weight, x, sum, na.rm = TRUE))
count[is.na(count)] <- 0
Expand Down