2

I have a large dataset, which I want to plot. Unfortunately the PDF-file becomes very large, and the PDF readers need long time to show the plot (which can be annoying, when you want to scroll).

l = 1e6
x = 1:l
y = x * 2 + runif(l)

pdf("points.pdf")
plot(x, y)
dev.off()

pdf("lines.pdf")
plot(x, y, type="l")
dev.off()

If I use lines instead of points, there is less problems. This made me think, that there might be a compression or lowered resolution used when creating PDF files. Also when I add the plot to a LaTeX file, LaTeX seems to lower the resolution.

I there a parameter I can use to lower the resolution?.

R_User
  • 10,682
  • 25
  • 79
  • 120
  • 2
    A suggestion that I have received once for heavy PDF plots was to use PNG instead, and then insert the image into the PDF document. – Maxim.K Apr 22 '13 at 08:51
  • The PDF plot will be vector graphics so I don't think being able to change the DPI will do anything, it's to do with the number of points being plotted. `pdf()` also has a `compress` argument, but this is set to `TRUE` by default. – Simon O'Hanlon Apr 22 '13 at 08:56
  • I also thought of plotting only every 10th datapoint, but (1) I was not sure how to do it and (2) for some plot this does not work. – R_User Apr 22 '13 at 08:58
  • 2
    check out the [bigvis](https://github.com/hadley/bigvis) package – baptiste Apr 22 '13 at 09:08
  • 1
    using `pch="."` would help somewhat. – Ben Bolker Mar 26 '14 at 22:12

1 Answers1

1

I suggest to think about your choice of plot. I would make a hexbin plot instead:

library(hexbin)
bindata <- hexbin(x,y,xbins=100)
plot(bindata)

This allows you to make a vector graphic and to better present the information in your data visually.

enter image description here

PS: Package ggplot2 can also produce hexbin plots, presumably nicer looking ones.

Roland
  • 127,288
  • 10
  • 191
  • 288