简体   繁体   中英

plotly-r: specifying size of marker in add_trace() reduces opacity of markers

I am using plotly in R (R package version 4.9.2.1). I find that when I use a size argument in add_trace() , the opacity of the markers in the trace is reduced. This seems like a bug. Is it -- or am I just failing to understand add_trace() ?

Here is a minimal example:

library(plotly)
myPlot <- plot_ly(data = data.frame(x = 1, y = 1, yLo = 0.5, yHi = 1.5)) 
myPlot <- add_trace(
  myPlot,
  x = ~x, y = ~y,
  type = "scatter", mode = "markers",
  size   = 1000,
  marker = list(
    # size    = 250,
    # opacity = 1,
    color = "D0D0D0",
    line  = list(color = "D0D0D0")))
add_segments(  
  myPlot,
  x = ~x, xend = ~x, y = ~yLo, yend = ~yHi, 
  color = I("#D0D0D0"))

The code produces this image:

点与垂直线相交

You can see that the opacity of the dot and the line differ, even though nothing in the code suggests that they should differ. (I have zoomed in on the dot to make this difference easy to see.)

There are at least three ways to fix the problem:

  1. Comment out size = 1000 .
  2. Uncomment size = 250 in the marker argument.
  3. Uncomment opacity = 1 in the marker argument.

If I do any of those, the dot is completely opaque, just as the line is.

Note that this difference in opacities doesn't seem to be a matter of the dot and the line having different defaults. If that were the case, we wouldn't be able to solve the problem by manipulating the size arguments.

Is the default behavior demonstrated here a bug?

No, this is as intended and we don't consider it a bug: very often, sizing markers causes more occlusion and so by default opacity is lowered when size is used. If this is not desired, the best thing to do is to force opacity back to 1 explicitly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM