Skip to content

Commit a4ba0bd

Browse files
committed
width and height are parameters of geom_tile.
Fixes #1513
1 parent a700e7b commit a4ba0bd

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

NEWS.md

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

3+
* `geom_tile()` once again accepts `width` and `height` parameters (#1513).
4+
35
* Add access to `bw` argument of `density` in `stat_density`, which makes
46
it easy to get consistent smoothing between facets for example (@jiho)
57

R/geom-tile.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ geom_tile <- function(mapping = NULL, data = NULL, stat = "identity",
7979
#' @export
8080
#' @include geom-rect.r
8181
GeomTile <- ggproto("GeomTile", GeomRect,
82+
extra_params = c("na.rm", "width", "height"),
83+
8284
setup_data = function(data, params) {
8385
data$width <- data$width %||% params$width %||% resolution(data$x, FALSE)
8486
data$height <- data$height %||% params$height %||% resolution(data$y, FALSE)

tests/testthat/test-geom-tile.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
context("geom_tile")
2+
3+
test_that("accepts width and height params", {
4+
df <- data.frame(x = c("a", "b"), y = c("a", "b"))
5+
6+
out1 <- layer_data(ggplot(df, aes(x, y)) + geom_tile())
7+
expect_equal(out1$xmin, c(0.5, 1.5))
8+
expect_equal(out1$xmax, c(1.5, 2.5))
9+
10+
out2 <- layer_data(ggplot(df, aes(x, y)) + geom_tile(width = 0.5, height = 0.5))
11+
expect_equal(out2$xmin, c(0.75, 1.75))
12+
expect_equal(out2$xmax, c(1.25, 2.25))
13+
})

0 commit comments

Comments
 (0)