r - Reduce PDF file size of plots by filtering hidden objects -
while producing scatter plots of many points in r (using ggplot()
example), there might many points behind others , not visible @ all. instance see plot below:
this scatter plot of several hundreds of thousands points, of them behind other points. problem when casting output vector file (a pdf file example), invisible points make file size big, , increase memory , cpu usage while viewing file.
a simple solution cast output bitmap picture (tiff or png example), lose vector quality , can larger in size. tried online pdf compressors, result same size original file.
is there solution? example way filter points not visible, possibly during generating plot or after editing pdf file?
as start can this:
set.seed(42) df <- data.frame(x=x<-runif(1e6),y=x+rnorm(1e6,sd=0.1)) plot(y~x,data=df,pch=".",cex=4)
pdf size: 6334 kb
df2 <- data.frame(x=round(df$x,3),y=round(df$y,3)) df2 <- df[!duplicated(df2),] nrow(df2) #[1] 373429 plot(y~x,data=df2,pch=".",cex=4)
pdf size: 2373 kb
with rounding can control how many values want remove. need modify handle different colours.
Comments
Post a Comment