对于以下对象:
rawData <-
structure(list(obs = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), key = structure(1:8, .Label = c("sadness",
"neutral", "contempt", "disgust", "anger", "surprise", "fear",
"happiness"), class = "factor"), value = c(2.36220472440945,
89.3700787401575, 0.393700787401575, 0.78740157480315, 0, 0.78740157480315,
0, 6.2992125984252)), .Names = c("obs", "key", "value"), row.names = c(NA,
8L), class = "data.frame")
我希望在为每个条形指定颜色的同时创建一个绘图条形图。不幸的是,它只需要 n-1 种颜色,为剩余的颜色创建自己的“渐变”。
rawData %>%
group_by(obs) %>%
plot_ly(x = obs,
y = value,
type = "bar",
color = key,
colors = c("blue","grey","darkred","green","orange","black","purple"))
如果我尝试添加第 8 种颜色...
rawData %>%
group_by(obs) %>%
plot_ly(x = obs,
y = value,
type = "bar",
color = key,
colors = c("blue","grey","darkred","green","orange","black","purple","yellow"))
现在所有的酒吧都是黄色的。