Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Chris", "Parmer", role = c("aut", "cph"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.0.12 -- 11 Dec 2015

Fix #221

2.0.11 -- 11 Dec 2015

Fix #250
Expand Down
8 changes: 8 additions & 0 deletions R/trace_generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-cookbook-scatterplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

28 changes: 28 additions & 0 deletions tests/testthat/test-ggplot-jitter.R
Original file line number Diff line number Diff line change
@@ -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))
})