title: Reduce PDF file size of plots by filtering hidden objects
body: <p>While producing scatter plots of many points in R (using <code>ggplot()</code> for example), there might be many points that are behind the others and not visible at all. For instance see the plot below:</p>
  
  <p><img src="https://i.stack.imgur.com/ehJEo.png" alt="enter image description here"></p>
  
  <p>This is a scatter plot of several hundreds of thousands points, but most of them are behind the other points. The problem is when casting the output to a vector file (a PDF file for example), the invisible points make the file size so big, and increase memory and cpu usage while viewing the file.</p>
  
  <p>A simple solution is to cast the output to a bitmap picture (TIFF or PNG for example), but they lose the vector quality and can be even larger in size. I tried some online PDF compressors, but the result was the same size as my original file.</p>
  
  <p>Is there any good solution? For example some way to filter the points that are not visible, possibly during generating plot or after it by editing PDF file?</p>