Skip to content

Commit 24f81d0

Browse files
committed
Added test case
1 parent 1b579dc commit 24f81d0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: R/plotly_build.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,9 @@ map_color <- function(traces, stroke = FALSE, title = "", colorway, na.color = "
890890
# 3D needs a z property
891891
if ("scatter3d" %in% types) {
892892
colorBarTrace$type <- "scatter3d"
893-
colorBarTrace$z <- range(unlist(lapply(traces, "[[", "z")), na.rm = TRUE)
893+
zValues <- unlist(lapply(traces, "[[", "x"))
894+
zValues <- if (is.numeric(zValues)) range(zValues, na.rm = TRUE) else zValues
895+
colorBarTrace$z <- zValues
894896
}
895897
if (length(type <- intersect(c("scattergeo", "scattermapbox"), types))) {
896898
colorBarTrace$type <- type

Diff for: tests/testthat/test-plotly-color.R

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ test_that("Mapping a factor variable to color works", {
2020
expect_equivalent(length(cols), 3)
2121
})
2222

23+
test_that("A scatterplot with a factor variable and discrete color works", {
24+
d <- palmerpenguins::penguins
25+
p <- plot_ly(d, x = ~bill_length_mm, y = ~sex, color = ~bill_depth_mm,
26+
type = 'scatter', mode = 'markers')
27+
l <- expect_traces(p, 2, "scatterplot-factor-continous-color")
28+
})
29+
2330
test_that("Custom RColorBrewer pallette works for factor variable", {
2431
d <- palmerpenguins::penguins %>%
2532
filter(!is.na(bill_length_mm))

0 commit comments

Comments
 (0)