如何创建每个条形颜色不同的条形图,并添加带有每个条形名称和所用颜色(不是颜色名称,颜色本身)的图例。
library(plotly)
fig <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
fig
答案 0 :(得分:2)
有一个 color
参数
fig <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = c("giraffes", "orangutans", "monkeys"),
type = "bar", color = c('red', 'blue', 'green')
)
fig