Speed up plot() function for large dataset

前端 未结 5 1669
旧时难觅i
旧时难觅i 2020-11-29 07:15

I am using plot() for over 1 mln data points and it turns out to be very slow.

Is there any way to improve the speed including programming and hardware

5条回答
  •  不知归路
    2020-11-29 08:03

    It hasn't been mentioned here, but plotting to a high-resolution raster image is another reasonable choice (if you really want to plot a giant blob :-) ). It will be very slow to create, but the resulting image will be a reasonable size, and will open quickly. Because PNGs compress the file based on similarity of neighboring pixels, the exterior (all-white) and interior (all-black) of the blob don't take any more storage space as the resolution gets larger - all you're doing is rendering the edge of the blob in more detail.

    set.seed(101)
    a<-rnorm(1E7,1,1)
    b<-rnorm(1E7,1,1)
    png("blob.png",width=1000,height=1000)
    system.time(plot(a,b)) ## 170 seconds on an old Macbook Pro
    dev.off()
    

    The resulting image file is 123K, and could be made much higher-resolution with a small increase in rendering size (both in creating and opening the file) and file size.

提交回复
热议问题