gpt4 book ai didi

r - 颜色数 = 类别数的 plotly 条形图

转载 作者:行者123 更新时间:2023-12-01 11:29:00 25 4
gpt4 key购买 nike

对于以下对象:

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

现在所有的条都是黄色的。

最佳答案

使用 color 参数代替 marker 参数。

rawData %>% 
group_by(obs) %>%
plot_ly(x = obs,
y = value,
type = "bar",
color = key,
marker = list(color=c("blue","grey","darkred","green","orange","black","purple","yellow")))

关于r - 颜色数 = 类别数的 plotly 条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34797977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com