Setting my plotly marker size as a variable is not working when using frame (i.e. animated graph)

夙愿已清 提交于 2020-12-13 09:42:56

问题


I'm struggling to get my marker size to work as expected when I'm using it in an animated graph. Using a data set like below, I'd want the marker in column 1 to increase in size, then decrease; the marker in 2 to decrease in size, then increase; etc.:

data <- data.frame(xaxis = rep(as.character(c(1:5)), each = 10), 
                   yaxis = rep(c(1:5,5:1), 5), 
                   size = c(
                       c(1:5,5:1),
                       c(5:1,1:5),
                       c(1:10),
                       c(10:1),
                       rep(c(1,10), 5)
                   ),
                    frame = c(1:10)
                   )


Frustratingly, when I run just one marker (i.e. data is data[data$xaxis == 1, ]), everything works as expected; but by the time show all 5 markers, the sizes go haywire.

How can I get better control of my marker size?

Example plot:

plot_ly(
    data = data,
    x = ~xaxis,
    y = ~yaxis,
    frame = ~frame,
    type = 'scatter',
    marker = list(size = ~size*10),
    mode = 'markers'
)

回答1:


Not sure why, but it works fine, once you order your data according to your frames:

library(plotly)

data <- data.frame(xaxis = rep(as.character(c(1:5)), each = 10), 
                   yaxis = rep(c(1:5,5:1), 5), 
                   size = c(
                     c(1:5,5:1),
                     c(5:1,1:5),
                     c(1:10),
                     c(10:1),
                     rep(c(1,10), 5)
                   ),
                   frame = c(1:10)
)

data <- data[order(data$frame),]

plot_ly(
  data = data,
  x = ~xaxis,
  y = ~yaxis,
  frame = ~frame,
  type = 'scatter',
  marker = list(size = ~size*10),
  mode = 'markers'
)

You might want to file an issue regarding this.



来源:https://stackoverflow.com/questions/64046905/setting-my-plotly-marker-size-as-a-variable-is-not-working-when-using-frame-i-e

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!