糟糕的表现。如何到处走走?

时间:2017-05-15 14:30:00

标签: r ggplot2 plotly

我们正在使用plot_ly来显示科学数据。当我们绘制“小”数据集时,它就像一个魅力。但是,当使用大型数据集时,它变得非常慢。我们想知道是否有一些提高性能的技巧,例如:在缩放时禁用悬停或避免重新缩放。

我们使用ggplotly从我们的ggplot代码进行翻译,但我们已经尝试直接使用plot_ly %>% add_polygonsplot_ly(..., type="scatter", mode="lines", fill="toself"),但在性能方面没有任何好处。

有任何想法吗?

plotly变慢的示例代码:

library(dplyr)
library(ggplot2)
library(plotly)

myfakedatagenerator <- function(sz){
    aux <- data.frame(
        Value = factor(sample(c("abc", "qwe", "xyz", "asd"), size=sz, replace=TRUE)),
        Resource = factor(sample(28, size=sz, replace=TRUE)),
        Duration = sample(20, size=sz, replace = TRUE)
    )
    aux <- aux %>% group_by(Resource) %>% mutate(End=cumsum(Duration))
    aux <- aux %>% group_by(Resource) %>% mutate(Start=End-Duration)
    aux 
}

tmp <- myfakedatagenerator(10000)

gg <- ggplot(tmp, aes(x=Start, y=Resource)) + 
      geom_rect(aes(xmin=Start, xmax=End,
                    ymin=as.numeric(Resource)-.4,
                    ymax=as.numeric(Resource)+.4,
                    fill=Value,
                    a=Start,
                    b=Value,
                    c=Duration
                    )) +
      scale_x_continuous("") + scale_y_discrete()

ggplotly(gg)

0 个答案:

没有答案
相关问题