Skip to content

Use transparent scatter lines for errorbars. Fixes #513. #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 1, 2016
Merged
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.js'
Version: 3.4.9
Version: 3.4.10
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
email = "[email protected]"),
person("Chris", "Parmer", role = c("aut", "cph"),
Expand Down
7 changes: 6 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
3.4.10 -- 1 Apr 2016

BUGFIX:

Fix a geom_errorbar bug introduced in 3.4.9. See #513.

3.4.9 -- 25 Mar 2016

BUGFIX:

Upgrade to plotlyjs 1.7.0. Fixes #513


3.4.8 -- 23 Mar 2016

BUGFIX:
Expand Down
4 changes: 2 additions & 2 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ make_error <- function(data, params, xy = "x") {
text = data$hovertext,
type = "scatter",
mode = "lines",
opacity = 0,
line = list(color = color)
opacity = aes2plotly(data, params, "alpha"),
line = list(color = "transparent")
)
e[[paste0("error_", xy)]] <- list(
array = data[[paste0(xy, "max")]] - data[[xy]],
Expand Down
23 changes: 19 additions & 4 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ if (report_diffs || build_table) {
message("Spinning up an independent R session with plotly's master branch installed")
Rserve::Rserve(args = "--vanilla --RS-enable-remote")
conn <- RSconnect()
# master version should _always_ depend on the CRAN version of ggplot2
# ensure the seed is the same for randomized tests
set.seed(1)
RSeval(conn, "set.seed(1)")
# we don't make assumptions about ggplot2 versioning,
# but it is _strongly_ recommended to use the CRAN version (of ggplot2)
RSeval(conn, "devtools::install_github('ropensci/plotly')")
RSeval(conn, "library(plotly)")
if (report_diffs) {
Expand All @@ -23,6 +27,19 @@ if (report_diffs || build_table) {
master_hash <- substr(master_hash, 1, 7)
# plotly-test-table repo hosts the diff pages & keeps track of previous versions
table_dir <- normalizePath("../../plotly-test-table", mustWork = T)
# Make sure we have appropriate versions of plotlyjs
# (see plotly-test-table/template/template/index.html)
file.copy(
file.path("..", "inst", "htmlwidgets", "lib", "plotlyjs", "plotly-latest.min.js"),
file.path(table_dir, "template", "New.min.js"),
overwrite = TRUE
)
download.file(
"https://raw.githubusercontent.com/ropensci/plotly/master/inst/htmlwidgets/lib/plotlyjs/plotly-latest.min.js",
file.path(table_dir, "template", "Old.min.js"),
method = "curl"
)
# directory for placing test differences
this_dir <- file.path(table_dir, this_hash)
if (dir.exists(this_dir)) {
message("Tests were already run on this commit. Nuking the old results...")
Expand Down Expand Up @@ -102,9 +119,7 @@ save_outputs <- function(gg, name) {
dir.create(test_dir, recursive = T)
# copy over diffing template
file.copy(
file.path(table_dir, "template", "template", "index.html"),
test_dir,
recursive = T
dir(file.path(table_dir, "template", "template"), full.names = TRUE), test_dir
)
# overwrite the default JSON
writeLines(
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-ggplot-jitter.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ expect_traces <- function(gg, n_traces, name) {
list(traces = has_data, layout = L$layout)
}

set.seed(1001)
p <- ggplot(mpg, aes(cyl, hwy)) + geom_jitter()

test_that("geom_jitter is working", {
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-mean-error-bars.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ test_that("different colors for error bars, points, and lines", {
geom_point(color = "blue", size = 14)
L <- save_outputs(one.line.gg, "error-simple-line-point-crazy")
})

# example from https://github.com/ropensci/plotly/issues/513

d <- data.frame(
x = 1:5,
y = 1:5,
label = letters[1:5],
group = factor(c('one', 'one', 'two', 'two', 'one'))
)
fig1 <- ggplot(d, aes(x = x, y = y, text = label, colour = group)) +
geom_rect(fill = 'lightgrey', colour = 'lightgrey',
xmin = 3, xmax = 4, ymin = -4, ymax = 7) +
geom_point() + geom_errorbarh(aes(xmin = x - 1, xmax = x + 2), alpha = 0.5) +
theme_bw()

test_that("error bars respect trace ordering", {
L <- save_outputs(fig1, "error-rect-alpha")
})