【发布时间】:2018-11-15 00:19:00
【问题描述】:
有人知道如何将以下类型的图例添加到 R plot_ly 图表中吗?
请在下面找到一个可复制的示例
在这个例子中,条形颜色取决于速度值:我想打印上面提到的图例,而不仅仅是得到“trace 0”......
library(plotly)
library(data.table)
example_data <- data.table(x = c(1,2,3,4,5,6), y = c(7,9,4,3,8,9), velocity = c(0.6,1.4,5,4,0.2,1.1))
example_data$color <- cut(example_data$velocity,breaks = c(0,0.8,1.2,1.5,10),labels = c("lightgreen","darkgreen","yellow","red"))
plot_ly(data = example_data, x = ~ x,y = ~y ,color = ~ I(color),type = "bar") %>%
layout(showlegend = TRUE)
非常感谢!
【问题讨论】: