Skip to content

Commit 5cfcaa0

Browse files
committed
Fix size and alpha translation for points. Fixes #386
1 parent d199cb8 commit 5cfcaa0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

R/trace_generation.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ geom2trace <- list(
590590
)
591591
},
592592
point=function(data, params){
593+
# params contains unique values, but we need _all_ values from the data
594+
for (i in names(params)) {
595+
if (length(params[[i]]) > 1) params[[i]] <- data[[i]]
596+
}
593597
L <- list(
594598
x = data$x,
595599
y = data$y,

tests/testthat/test-ggplot-point.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
context("geom_point")
2+
3+
expect_traces <- function(gg, n.traces, name){
4+
stopifnot(is.ggplot(gg))
5+
stopifnot(is.numeric(n.traces))
6+
L <- save_outputs(gg, paste0("smooth-", name))
7+
all.traces <- L$data
8+
no.data <- sapply(all.traces, function(tr) {
9+
is.null(tr[["x"]]) && is.null(tr[["y"]])
10+
})
11+
has.data <- all.traces[!no.data]
12+
expect_equal(length(has.data), n.traces)
13+
list(traces=has.data, layout=L$layout)
14+
}
15+
16+
test_that("geom_point size & alpha translate to a single trace", {
17+
gg <- ggplot(mtcars, aes(cyl, wt)) +
18+
geom_point(aes(size = gear, alpha = cyl))
19+
info <- save_outputs(gg, "point-size-alpha")
20+
expect_equal(length(info$data), 1)
21+
mkr <- info$data[[1]]$marker
22+
expect_equal(length(mkr$size), nrow(mtcars))
23+
expect_equal(length(mkr$opacity), nrow(mtcars))
24+
})

0 commit comments

Comments
 (0)