Skip to content

Commit d36e919

Browse files
committed
Merge pull request #1464 from has2k1/fix-statdensity2d
Fix statdensity2d
2 parents 38237d0 + 91c8bf1 commit d36e919

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# ggplot2 2.0.0.9000
22

3+
## Bug fixes and minor improvements
4+
5+
* `stat-density-2d()` no longer ignores the `h` parameter.
6+
7+
* `stat-density-2d()` now accepts `bins` and `binwidth` parameters
8+
to control the number of contour levels (#1448, @has2k1).
9+
310
# ggplot2 2.0.0
411

512
## Major changes

R/stat-density-2d.r

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ stat_density_2d <- function(mapping = NULL, data = NULL, geom = "density_2d",
2323
na.rm = na.rm,
2424
contour = contour,
2525
n = n,
26+
h = h,
2627
...
2728
)
2829
)
@@ -43,7 +44,8 @@ StatDensity2d <- ggproto("StatDensity2d", Stat,
4344
required_aes = c("x", "y"),
4445

4546
compute_group = function(data, scales, na.rm = FALSE, h = NULL,
46-
contour = TRUE, n = 100) {
47+
contour = TRUE, n = 100, bins = NULL,
48+
binwidth = NULL) {
4749
if (is.null(h)) {
4850
h <- c(MASS::bandwidth.nrd(data$x), MASS::bandwidth.nrd(data$y))
4951
}
@@ -56,7 +58,7 @@ StatDensity2d <- ggproto("StatDensity2d", Stat,
5658
df$group <- data$group[1]
5759

5860
if (contour) {
59-
StatContour$compute_panel(df, scales)
61+
StatContour$compute_panel(df, scales, bins, binwidth)
6062
} else {
6163
names(df) <- c("x", "y", "density", "group")
6264
df$level <- 1

0 commit comments

Comments
 (0)