Skip to content

Commit 1993631

Browse files
committed
Merge pull request #224 from ropensci/baobao-geom_jitter
Making geom_jitter work
2 parents ef440d2 + 62c34ba commit 1993631

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library
3-
Version: 2.0.11
3+
Version: 2.0.12
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "[email protected]"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.0.12 -- 11 Dec 2015
2+
3+
Fix #221
4+
15
2.0.11 -- 11 Dec 2015
26

37
Fix #250

R/trace_generation.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ toBasic <- list(
401401
g$params$yend <- max(g$prestats.data$globymax)
402402
g
403403
},
404+
jitter=function(g) {
405+
if ("size" %in% names(g$data)) {
406+
g$params$sizemin <- min(g$prestats.data$globsizemin)
407+
g$params$sizemax <- max(g$prestats.data$globsizemax)
408+
}
409+
g$geom <- "point"
410+
g
411+
},
404412
point=function(g) {
405413
if ("size" %in% names(g$data)) {
406414
g$params$sizemin <- min(g$prestats.data$globsizemin)

tests/testthat/test-cookbook-scatterplots.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ g <- ggplot(dat, aes(x=xrnd, y=yrnd)) +
7171
geom_point(shape=1, # Use hollow circles
7272
position=position_jitter(width=1,height=.5))
7373
save_outputs(g, "scatterplots-jitter")
74+
75+
# Jitter the points using geom_jitter
76+
# Jitter range is 1 on the x-axis, .5 on the y-axis
77+
g <- ggplot(dat, aes(x = xrnd, y = yrnd)) +
78+
geom_jitter(shape = 1, # Use hollow circles
79+
width = 1, height = 0.5)
80+
save_outputs(g, "scatterplots-geom_jitter")
81+

tests/testthat/test-ggplot-jitter.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
context("geom_jitter")
2+
3+
# Expect trace function
4+
expect_traces <- function(gg, n_traces, name) {
5+
stopifnot(is.ggplot(gg))
6+
stopifnot(is.numeric(n_traces))
7+
save_outputs(gg, paste0("jitter-", name))
8+
L <- gg2list(gg)
9+
all_traces <- L$data
10+
no_data <- sapply(all_traces, function(tr) {
11+
is.null(tr[["x"]]) && is.null(tr[["y"]])
12+
})
13+
has_data <- all_traces[!no_data]
14+
expect_equal(length(has_data), n_traces)
15+
list(traces = has_data, layout = L$layout)
16+
}
17+
18+
set.seed(1001)
19+
p <- ggplot(mpg, aes(cyl, hwy)) + geom_jitter()
20+
21+
test_that("geom_jitter is working", {
22+
info <- expect_traces(p, 1, "basic")
23+
tr <- info$traces[[1]]
24+
expect_identical(tr$type, "scatter")
25+
# default jitter is 40% of the resolution of the data.
26+
diffs <- abs(mpg$cyl - tr$x)
27+
expect_true(all(0 < diffs & diffs < 0.4))
28+
})

0 commit comments

Comments
 (0)