Graphic package faster than ggplot2 [closed]

3

Do you know of any packages in R that concatenate and make 2D and 3D graphics faster than ggplot2?

    
asked by anonymous 19.04.2016 / 18:23

1 answer

5

The base itself is much faster than the ggplot2 in terms of time to render the chart.

> library(ggplot2)
> dados <- data.frame(x = 1:10, y = 1:10)
> microbenchmark::microbenchmark(
+   base = plot(dados$x, dados$y),
+   ggplot2 = print(ggplot(dados, aes(x, y)) + geom_point()),
+   times = 10)
Unit: milliseconds
    expr        min         lq      mean   median        uq       max neval
    base   6.111439   6.297696  11.23991  13.0963  13.68068  14.21597    10
 ggplot2 137.465155 139.280801 148.73481 148.4097 155.98191 161.27931    10

But if you are having problems because ggplot is taking a long time, you should consider taking a sample of your data to make the chart. Usually for the preview should not make much difference.

If you are trying to make frequency charts, you can try to group the data using some other package and then using ggplot just to plot. For example, if you wanted to make a bar chart of the colors of diamonds (database diamonds of R).

I could do this:

diamonds %>% 
    group_by(color) %>%
    summarise(n = n()) %>%
    ggplot(aes(x = color, y = n)) + 
    geom_bar(stat = "identity")

Instead of doing so:

ggplot(diamonds, aes(x = color)) + geom_bar()

The form using dplyr will be a little faster:

Unit: milliseconds
           expr      min       lq     mean   median       uq      max neval
 ggplot + dplyr 154.2552 159.4668 165.0565 162.5604 172.0724 180.2274    10
         ggplot 205.3213 212.5129 218.5641 217.9931 223.3510 238.7627    10
    
19.04.2016 / 22:05