diff --git a/DESCRIPTION b/DESCRIPTION index 9582928e1e..0ee1405acf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: plotly Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library -Version: 2.0.11 +Version: 2.0.12 Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"), email = "cpsievert1@gmail.com"), person("Chris", "Parmer", role = c("aut", "cph"), diff --git a/NEWS b/NEWS index 88d1df09ec..712f4a1097 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +2.0.12 -- 11 Dec 2015 + +Fix #221 + 2.0.11 -- 11 Dec 2015 Fix #250 diff --git a/R/trace_generation.R b/R/trace_generation.R index fae9fef4a1..28b3cde411 100644 --- a/R/trace_generation.R +++ b/R/trace_generation.R @@ -401,6 +401,14 @@ toBasic <- list( g$params$yend <- max(g$prestats.data$globymax) g }, + jitter=function(g) { + if ("size" %in% names(g$data)) { + g$params$sizemin <- min(g$prestats.data$globsizemin) + g$params$sizemax <- max(g$prestats.data$globsizemax) + } + g$geom <- "point" + g + }, point=function(g) { if ("size" %in% names(g$data)) { g$params$sizemin <- min(g$prestats.data$globsizemin) diff --git a/tests/testthat/test-cookbook-scatterplots.R b/tests/testthat/test-cookbook-scatterplots.R index 99676a1558..57d7d35097 100644 --- a/tests/testthat/test-cookbook-scatterplots.R +++ b/tests/testthat/test-cookbook-scatterplots.R @@ -71,3 +71,11 @@ g <- ggplot(dat, aes(x=xrnd, y=yrnd)) + geom_point(shape=1, # Use hollow circles position=position_jitter(width=1,height=.5)) save_outputs(g, "scatterplots-jitter") + +# Jitter the points using geom_jitter +# Jitter range is 1 on the x-axis, .5 on the y-axis +g <- ggplot(dat, aes(x = xrnd, y = yrnd)) + + geom_jitter(shape = 1, # Use hollow circles + width = 1, height = 0.5) +save_outputs(g, "scatterplots-geom_jitter") + diff --git a/tests/testthat/test-ggplot-jitter.R b/tests/testthat/test-ggplot-jitter.R new file mode 100644 index 0000000000..b995795be4 --- /dev/null +++ b/tests/testthat/test-ggplot-jitter.R @@ -0,0 +1,28 @@ +context("geom_jitter") + +# Expect trace function +expect_traces <- function(gg, n_traces, name) { + stopifnot(is.ggplot(gg)) + stopifnot(is.numeric(n_traces)) + save_outputs(gg, paste0("jitter-", name)) + L <- gg2list(gg) + all_traces <- L$data + no_data <- sapply(all_traces, function(tr) { + is.null(tr[["x"]]) && is.null(tr[["y"]]) + }) + has_data <- all_traces[!no_data] + expect_equal(length(has_data), n_traces) + list(traces = has_data, layout = L$layout) +} + +set.seed(1001) +p <- ggplot(mpg, aes(cyl, hwy)) + geom_jitter() + +test_that("geom_jitter is working", { + info <- expect_traces(p, 1, "basic") + tr <- info$traces[[1]] + expect_identical(tr$type, "scatter") + # default jitter is 40% of the resolution of the data. + diffs <- abs(mpg$cyl - tr$x) + expect_true(all(0 < diffs & diffs < 0.4)) +})