r - 填充颜​​色的完全不透明

标签 r plotly

我想在 R 中使用 Plotly 创建一个填充面积图。

可重现的例子:

library(plotly)
library(dplyr)

data <- data.frame(a = c("r","r","r","r","s","s","s","s"),
                   b = c(2,4,6,4,1,3,5,7),
                   c = c(1,2,3,4,1,2,3,4))
data %>% 
  plot_ly(x = ~c, y = ~b, split = ~a, type = 'scatter', mode = 'none', fill = 'tozeroy')

默认情况下,填充颜色具有 50% 的不透明度,但我希望它们具有 100% 的不透明度。 Plotly 提供了一个 opacity 和一个 alpha 参数,但它们都不影响填充颜色的不透明度。

我错过了什么吗?

最佳答案

也许您可以这样解决问题:

data_r <- data[data$a == 'r',]
data_s <- data[data$a == 's',]


plot_ly(x = data_r$c, y = data_r$b, split = data_r$a, type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = 'skyblue') %>%
  add_trace(x = data_s$c, y = data_s$b, split = data_s$a, type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = 'coral')

关于r - 填充颜​​色的完全不透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43135348/

相关文章:

r - 使用 ggplot 检测变化点

r - 使用plot_ly R包缩放点并选择颜色

r - 如何使用ggplot2、gridExtra对齐和缩放不同维度的图?

r - R函数中点/周期的用法

regex - 根据匹配的模式替换匹配项

r - 使用 dplyr 计算 2 列组合的平均值

r - plotly R : change hoverinfo font color according to different bar colors

python - 如何在pythonplotlyexpress中对x轴标签和图例进行排序?

r - 图例中的符号和颜色分开

python - 如何从 Pandas 数据框中的每一列创建子图