本文介绍了使用框架(即动画图)时,将我的绘图标记大小设置为变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在动画图中使用它时,我正在努力使标记大小能够按预期工作.使用下面的数据集,我希望第1列中的标记大小增加,然后减小;2中的标记大小减小,然后增大;等等:

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


令人沮丧的是,当我只运行一个标记时(即数据是 data [data $ xaxis == 1,] ),一切都按预期进行;但在显示所有5个标记时,大小变成了麻烦.

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?

示例图:

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

您可能要为此提出问题.

这篇关于使用框架(即动画图)时,将我的绘图标记大小设置为变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:48