ggobi / ggally

R package that extends ggplot2
http://ggobi.github.io/ggally/
588 stars 118 forks source link

Enable rasterization of ggpairs output? #459

Closed AlexBlais74 closed 1 year ago

AlexBlais74 commented 1 year ago

Hello I am wondering if there is a way to rasterize the scatter plots of the ggpairs output. I am working with 16 pairs, each consisting of about 20,000 data points, and saving to PDF makes for files that are too large. I would like retaining vectors for the plot annotations, but have the opportunity to rasterize the scatter plots themselves. Is there a possibility to achieve this? I tried using "ggrastr" to the ggpairs output, but ggrastr only takes ggplot objects as input. Thanks for any suggestion. Alex

schloerke commented 1 year ago

Neat package! Yes, that would not be fun to work with.

Does it work if you pull out the individual plots, rasterize them, and then put the plots back into the matrix?

# Untested code

pm <- ggpairs(....) # make your plot matrix object like normal
for (i in 1:pm$nrow) {
  for (j in 1:pm$ncol) {
    # `rasterize()` each plot
    # Might need to make sure it is a plot that should be `rasterize()`ed
    pm[i,j] <- rasterize(pm[i,j], layers='Point', dpi=50)
  }
}

# Print rasterized point panels
print(pm)
AlexBlais74 commented 1 year ago

This works like a charm and produces the expected output! Thanks for the super fast reply.