Skip to content

Commit ae0a349

Browse files
committed
geom_histogram(aes(fill = ..count..)) works; clean up
1 parent 75b4ca8 commit ae0a349

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

R/trace_generation.R

+2-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ layer2traces <- function(l, d, misc) {
4545
if (g$geom == "histogram") {
4646
g$geom <- "bar"
4747
bargap <- 0
48-
misc$hist <- TRUE
4948
}
5049

5150
# For non-numeric data on the axes, we should take the values from
@@ -161,16 +160,14 @@ layer2traces <- function(l, d, misc) {
161160
matched.names <- names(basic$data)[data.i]
162161
name.i <- name.names %in% matched.names
163162
invariable.names <- cbind(name.names, mark.names)[name.i,]
164-
# fill can be variable for histograms
165-
#if (misc$hist)
166-
# invariable.names <- invariable.names[!grepl("fill", invariable.names)]
167163
other.names <- !names(basic$data) %in% invariable.names
168164
vec.list <- basic$data[is.split]
169165
df.list <- split(basic$data, vec.list, drop=TRUE)
170166
lapply(df.list, function(df){
171167
params <- basic$params
172168
params[invariable.names] <- if (ncol(x <- df[1, invariable.names]) > 0) x else NULL
173-
list(data=df[other.names], params=params)
169+
list(data=df[other.names],
170+
params=params)
174171
})
175172
}
176173
}
@@ -250,7 +247,6 @@ layer2traces <- function(l, d, misc) {
250247
if (g$geom == "bar") {
251248
tr$bargap <- if (exists("bargap")) bargap else "default"
252249
pos <- l$position$.super$objname
253-
#browser()
254250
tr$barmode <- if (pos %in% c("identity", "stack", "fill")) {
255251
"stack"
256252
} else "group"

tests/testthat/test-ggplot-histogram.R

+9-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ test_that("geom_histogram(aes(y = ..density..)) displays a density", {
3838
expect_equal(area, 1, 0.1)
3939
})
4040

41-
# would be nice to have...
42-
# test_that("geom_histogram(aes(fill = ..count..)) works", {
43-
# info <- expect_traces(base + geom_histogram(aes(fill = ..count..)), 1, "fill")
44-
# tr <- info$traces[[1]]
45-
# ncolors <- length(tr$marker$color)
46-
# nbars <- sum(tr$y > 0)
47-
# expect_identical(ncolor, nbars)
48-
# })
41+
test_that("geom_histogram(aes(fill = ..count..)) works", {
42+
info <- expect_traces(base + geom_histogram(aes(fill = ..count..)), 6, "fill")
43+
tr <- info$traces
44+
# each traces should have the same value of y
45+
for (i in seq_along(traces)) {
46+
ys <- tr[[i]]$y
47+
expect_equal(length(unique(ys)), 1)
48+
}
49+
})
4950

5051
test_that("Fixed colour/fill works", {
5152
gg <- base + geom_histogram(colour = "darkgreen", fill = "white")

0 commit comments

Comments
 (0)