【问题标题】:Bar plot in red scale红色刻度条形图
【发布时间】: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 中做

标签: r plotly


【解决方案1】:

如果我是你,我会使用 R 中的 ggplot2 包。你可以将 ggplot 图直接输入 Plotly。

在此处查看备忘单:https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf

有一个函数 scale_fill_gradient() 可以在其中设置低值和高值。它可以完美地满足您的目的。

【讨论】:

  • 我遇到了一点困难,但我设法将 ggplot 与 plotly 结合使用,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多