We are using plotly to visualize scientific data as function time vs resources. For this, we use ggplotly with our classical ggplot2 code.
We represent activities with boxes drawn using geom_rect.
Our problem starts when we use a large dataset. Plotly visualizations become extremely lagged even in a robust machine (core i7 with 16gb of RAM). However, when we move to geom_segment, plotly performs well and it is possible to zoom and filter normally.
The question is that we cannot move to geom_segment because it has some strange behavior when scaling/zooming.
So, I would like to know if there is some option to enable/disable to achieve better performance with geom_rect as well we can obtain with geom_segment?
Example code:
library(plyr)
library(plotly)
myfakedatagenerator <- function(sz){
aux <- data.frame(
Value = sample(c("abc", "qwe", "xyz", "asd"), size=sz, replace=TRUE),
ResourceId = sample(28, size=sz, replace=TRUE),
Duration = sample(20, size=sz, replace = TRUE)
)
aux <- aux %>% group_by(ResourceId) %>% mutate(End=cumsum(Duration))
aux <- aux %>% group_by(ResourceId) %>% mutate(Start=End-Duration)
aux$ResourceId <- factor(aux$ResourceId)
aux
}
aux <- myfakedatagenerator(50000)
ggplotly(
ggplot(aux, aes(x=Start, y=ResourceId)) +
geom_rect(aes(xmin=Start, xmax=End,
ymin=as.numeric(ResourceId)-.4,
ymax=as.numeric(ResourceId)+.4,
fill=factor(Value)
)) +
scale_x_continuous("") + scale_y_discrete()
)
ggplotly(
ggplot(aux, aes(x=Start, y=ResourceId)) +
geom_segment(aes(xend=End,
yend=ResourceId,
color=Value),
size=6) +
scale_x_continuous("")
)