【发布时间】:2020-08-14 06:23:31
【问题描述】:
我想根据红色刻度上的值对每个条形进行着色。例如,最大的条将是黑色 rgb(0,0,0),最小的将是 rgb(80,0,0),而中间的则强度会有所不同。
下面的链接在python中有一个解决方案,我想用re和plotly来做
Changing color scale in seaborn bar plot
library(plotly)
city <- c("Paris", "New York", "Rio", "Salvador", "Curitiba", "Natal")
value <- c(10,20,30,10,10,10)
data <- data.frame(city, value, stringsAsFactors = FALSE)
data <- data[order(-data$value, data$city),]
data$city <- factor(data$city, levels = unique(data$city)[order(data$value, decreasing = FALSE)])
fig <- plot_ly(y = reorder(data$city,-data$value), x = data$value, type = "bar", orientation = 'h') %>% layout(yaxis = list(autorange = "reversed"))
fig
【问题讨论】:
-
我想在 R 中做