1

I'm currently practicing R but I found a problem when I tried to run my scatter plot with ggplot2, with only 700kb dataset. I don't know why it tooks so long I mean around 5-10 seconds only to run the plot. my pc is i7 7700HQ, and 16gb of ram

Fahsan
  • 25
  • 3
  • In order for people to help you, it would be helpful to add at least the code you are using to make the plot. Best would bet to add some [reproducible code](https://stackoverflow.com/help/minimal-reproducible-example) to make it easier to understand the problem and give you an answer. – Duccio A Apr 10 '20 at 14:02
  • thank you for the suggestion. I'm new here. @DuccioA – Fahsan Apr 12 '20 at 16:04

2 Answers2

0

It's pretty normal, you cannot expect a good rendering (and a reasonable rendering time) by plotting more than 1k or 10k points on a scatterplot. This is called "overplotting". What you can do: replace geom_point() by geom_hex() or stat_density_2d()

If you specifically need a scatter plot, I suggest trying rasterly. It will first aggregate in a smart way to produce rasters and then render the output.

Especially if you want to import your charts in another document, you need to limit the size and the number of objects to display (important for vector images).

Thomas Bury
  • 138
  • 1
  • 2
  • 8
0

That really depends on what plot libraries you are using but looking at the size, it seems that you are plotting around 100000 points which 5 seconds doesn't look too long to me. If using plot function here is some comparison which might help from this source: Speed up plot() function for large dataset and https://www.r-bloggers.com/accelerating-ggplot2-use-a-canvas-to-speed-up-rendering-plots/.

I have run the following code on my laptop and this is what I have got for 781.3 Kb:

x <- seq(1, 1000, length.out = 100000)

system.time(plot(x))
    user  system elapsed 
    0.28    3.00    3.42 
system.time(plot(x,pch=20))
    user  system elapsed 
    0.45    5.81    6.31 
system.time(plot(x,pch='.'))
    user  system elapsed 
    0.13    0.92    1.09 

You can see using pch the performance can improve substantially.