Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ggplot2 (development version)

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

* Make sure position_jitter creates the same jittering independent of whether it
is called by name or with constructor (@thomasp85, #2507)

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