I want to create a filled area chart with Plotly in R.
Reproducible example:
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')
By default, the fill colours have 50% opacity, but I want them to have 100% opacity. Plotly offers an opacity
as well as an alpha
parameter, but none of them affects the opacity of the fill colours.
Do I miss anything?
答案 0 :(得分:0)
也许你可以像这样解决问题:
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')