Skip to content

Commit 6ca2f13

Browse files
committed
Merge branch 'master' of https://github.com/ropensci/plotly into fix/print
2 parents 6908c3a + b6506ac commit 6ca2f13

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
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.16
3+
Version: 2.0.17
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.17 -- 22 Dec 2015
2+
3+
Fix #358
4+
15
2.0.16 -- 18 Dec 2015
26

37
Require ggplot2 2.0.0 or higher. For details, see #269.

R/plotly.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,13 @@ colorize <- function(dat, title = "") {
419419
}
420420
dat <- list(dat)
421421
} else { # discrete color scale
422-
dat <- traceify(dat, "color")
423-
lvls <- unlist(lapply(dat, function(x) unique(x[["color"]])))
422+
lvls <- unique(cols)
424423
N <- length(lvls)
425424
default <- if (is.ordered(cols)) viridis::viridis(N)
426425
else RColorBrewer::brewer.pal(N, "Set2")
427-
colors <- dat[[1]][["colors"]] %||% default
426+
colors <- dat[["colors"]] %||% default
428427
colz <- scales::col_factor(colors, levels = lvls, na.color = "transparent")(lvls)
428+
dat <- traceify(dat, "color")
429429
dat <- Map(function(x, y) { x[["marker"]] <- c(x[["marker"]], list(color = y)); x },
430430
dat, colz)
431431
}

tests/testthat/test-plotly.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ test_that("Custom RColorBrewer pallette works for factor variable", {
5959
expect_identical(sort(cols[1:3]), sort(colz))
6060
})
6161

62+
test_that("Passing hex codes to colors argument works", {
63+
colz <- c('#FE8268', '#81E8FE', '#FED681', '#81FED6', '#FE81A9')
64+
d <- data.frame(Category = LETTERS[1:5], Value = 1:5, stringsAsFactors = F)
65+
p <- plot_ly(d, x = Category, y = Value, type = "bar",
66+
color = Category, colors = colz)
67+
l <- expect_traces(p, 5, "bar-color-factor-custom")
68+
colz2 <- sapply(l$data, function(x) x[["marker"]][["color"]])
69+
expect_identical(sort(colz), sort(colz2))
70+
})
71+
6272
test_that("Mapping a numeric variable to color works", {
6373
p <- plot_ly(data = iris, x = Sepal.Length, y = Petal.Length,
6474
color = Petal.Width, mode = "markers")

0 commit comments

Comments
 (0)