情节错误条形图奇怪的配色方案

时间:2016-08-29 17:43:27

标签: r plot plotly

我在plotly::plot_ly观察到一个奇怪的选择,在指定组着色时为错误条着色:

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

如何指定每个点应与其错误栏具有相同的颜色?

1 个答案:

答案 0 :(得分:1)

如果您有color = type,请切换到group = type以获得所需的分组。

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))