我想在 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/