在R中并密谋。如何尝试使用Alpha来控制分组散点图的透明度。我遵循Plotly's fillcolor defaults to half-transparency, want no-transparency中的示例:
df <- data.frame(x = rep(LETTERS[1:5], 3),
y = rexp(15, rate = 0.5),
z = c(rep("Adam", 5), rep("Arthur", 5), rep("Ford", 5)))
df <- arrange(df, desc(z))
plot_ly(df, x = ~x, y = ~y, color = ~z, type = 'scatter', stackgroup = 'one',
groupnorm = 'percent', colors = gg_color(Nv), alpha = 1, alpha_stroke = 1)
Plotly's fillcolor defaults to half-transparency, want no-transparency中给出的解决方案起作用:
library(htmlwidgets)
library(htmltools)
fillOpacity = function(., alpha = 0.5) {
css = sprintf("<style> .js-fill { fill-opacity: %s !important; } </style>", alpha)
prependContent(., HTML(css))
}
plot_ly(df, x = ~x, y = ~y, color = ~z, type = 'scatter', stackgroup = 'one',
groupnorm = 'percent', colors = gg_color(Nv), alpha = 1, alpha_stroke = 1) %>%
fillOpacity(alpha = 1)
Works:
但是,在“闪亮”中给出以下警告,并且不透明性消失了>>
Warning in renderWidget(instance) : Ignoring prepended content; prependContent can't be used in a Shiny render call
是否有解决此问题的方法?
[注意:第二个图形是Windows中的一个片段,因为单击下载png绘图按钮时,第二个图形仍将图形下载为透明。这两个问题可能有关。
在R中并密谋。如何尝试使用Alpha来控制分组散点图的透明度。我遵循了Plotly的fillcolor默认为半透明的示例,希望没有-...
我看过这里https://plotly.com/python/filled-area-plots/,并使用了fill='tonexty'
。现在alpha = 1
工作并控制填充的透明度。