简体   繁体   English

使用框架(即动画图形)时,将我的绘图标记大小设置为变量不起作用

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

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;使用如下数据集,我希望第 1 列中的标记增大,然后减小; the marker in 2 to decrease in size, then increase; 2 中的标记减小大小,然后增加; 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 (ie data is data[data$xaxis == 1, ] ), everything works as expected;令人沮丧的是,当我只运行一个标记(即数据是data[data$xaxis == 1, ] )时,一切都按预期工作; but by the time show all 5 markers, the sizes go haywire.但是到了显示所有 5 个标记的时候,尺寸会变得混乱。

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'
)

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.您可能想就此提出问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Plotly 包创建动画折线图 - creating an animated line graph using Plotly package 在图中设置标记大小 - Set marker size in plotly Plotly 标记尺寸 - Plotly marker size 使用间接变量的rowSums(即使用字符串变量分配列号) - rowSums using an indirect variable (i.e. using a string variable to allocate the column numbers) 使用R计算纵向数据集的导数(即,一个变量基于另一个变量的更改) - Calculating derivative (i.e. change in one variable based on change in another variable) of longitudinal dataset using R 如何使用 R 在 plotly plot 中查看我用“size =”指定的变量的值(包:plotly) - How can I see the values of a variable that I specified with “size = ” in a plotly plot using R (package: plotly) 在绘图 R 中映射标记大小时发出虚假警告 - spurious warning when mapping marker size in plotly R python 等效于 group_by,使用 cur_group() 进行变异(即分组变量的值) - python equivalent of group_by, mutate using cur_group() (i.e. value of grouping variable) 为什么 dplyr filter() 不能在 function 中工作(即使用变量作为列名)? - Why doesn't dplyr filter() work within function (i.e. using variable for column name)? 如何渲染具有隐藏的预设轨迹(即基于列表的“ legendonly”)的绘图 - How to render a plotly plot with preset traces hidden i.e. 'legendonly' based on list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM