'Why is my interactive plotly scatter plot running so slowly?

I've created a plotly scatterplot; however, the interactive plot is currently working at ~1 FPS. I was wondering if anyone knew of a way to speed this up?

plot_total <-
  demo %>%
  as.data.frame() %>%
  ggplot(aes(log2(baseMean), log2FoldChange, color=padj < 0.01,
             text = paste(" log2(baseMean):", formatC(log2(baseMean), format = "e", digits = 2), "\n",
                          "log2FoldChange:", formatC(log2FoldChange, format = "e", digits = 2), "\n",
                          "Gene Name:", Gene, "\n",
                          "ENSG:", ENSG))) +
  geom_point(demo = . %>% filter(!padj<0.01), cex = 0.1, position=position_jitter(w=0.01,h=0.1), size=1) +
  geom_point(demo = . %>% filter(is.na(padj)), cex = 0.1, position=position_jitter(w=0.01,h=0.1), size=1) +
  geom_point(demo = . %>% filter(padj<0.01), cex = 1) +
  scale_color_manual(values=c("FALSE" = "#30B7BC", "TRUE" = "#DE653A", "NA" = "#B3B3B3")) +
  labs(title = "Treated vs. Control", x = "log2Expression") +
  theme_bw() +
  NULL

ggplotly(plot_total, tooltip = "text", type = 'scattergl')

I have tried changing the type = 'scattergl' and type = 'scatter' to increase performance, but this doesn't seem to change anything.

Is there a way to reduce the amount of points on the plot? I.e. only show points for padj<0.01.

plot



Solution 1:[1]

Solution was to add %>% toWebGL() and take advantage of hardware acceleration.

ggplotly(plot_total, tooltip = "text", type = 'scattergl') %>% toWebGL()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cixiwoc873