Efficient mapping of millions of data points in R

I am trying to build a million data points in R. I am currently using ggplot2 (but I am open to suggesting alternative packages). The problem is that the chart takes too much time to render (often above a minute). I'm looking for ways to do this faster - ideally in real time. I will be grateful for any help - adding code to the question for clarity.

Creating a (random) data frame with ~ 500000 data points:

letters <- c("A", "B", "C", "D", "E", "F", "G") myLetters <- sample(x = letters, size = 100000, replace = T) direction <- c("x", "y", "z") factor1 <- sample(x = direction, size = 100000, replace = T) factor2 <- runif(100000, 0, 20) factor3 <- runif(100000, 0, 100) decile <- sample(x = 1:10, size = 100000, replace = T) new.plot.df <- data.frame(letters = myLetters, factor1 = factor1, factor2 = factor2, factor3 = factor3, decile = decile) 

Now, let's build the data:

 color.plot <- ggplot(new.plot.df, aes(x = factor3, y = factor2, color = factor1)) + geom_point(aes(alpha = factor2)) + facet_grid(decile ~ letters) 

enter image description here

How to make rendering faster?

+7
r plot ggplot2
source share
1 answer

In general, I use two strategies for this:

1) As described in the comments, using a reasonable descriptive sample of your data will not affect your plot, and you will reduce the number of displayed points.

2) One trick that I use is to actually create an object without displaying a graph, and instead save the graph in a PNG image. This actually speeds up the process, because when you open the image, it will be a bitmap, not a vector image.

+1
source share

All Articles