mlegge
mlegge

Reputation: 6913

plotly error bar plot strange color scheme

I am observing a strange choice from plotly::plot_ly to color the error bars when a group coloring is specified:

library("data.table")
library("plotly")
dat <- data.table(
  low_diff = c(2, 3, 1)
  , high_diff = c(3, 4, 1)
  , point = c(10, 11, 9)
  , type = LETTERS[1:3]
)
plot_ly(data = dat, y = type, x = point, mode = "markers", color = type,
        error_x = list(type = "data", symmetric = FALSE,
                       array = high_diff, arrayminus = low_diff))

enter image description here

How can I specify that each point should have the same color as its error bar?

Upvotes: 0

Views: 504

Answers (1)

Jota
Jota

Reputation: 17611

Where you have color = type, switch to group = type to get the desired grouping.

plot_ly(data = dat, y = type, x = point, mode = "markers", group = type,
        error_x = list(type = "data", symmetric = FALSE,
                       array = high_diff, arrayminus = low_diff))

Upvotes: 1

Related Questions