-1

I am trying to include a single, less than one-page-sized plot into a Sweave/R pdf document. This plot is based on huge amounts of data - i.e. in a small plot area there are tens of thousands of points. Whenever I include the plot normally through Sweave, I get huge lag when I open the resulting pdf. This is similar to the case of exporting an eps with tens of thousands of dots - even though the plot area is small it will lag heavily.

How do I code it such that a png is inserted, or equivalent, which doesn't keep all the information of every dot in the plot but just keeps the information of the pixels corresponding to the plot size?

\begin{figure}
\begin{center}
<<fig=TRUE,echo=FALSE,height=4>>=
plot(rnorm(100000))
@
\end{center}
\caption{Visualisation in Sweave which can lag computers}
\end{figure}

I am looking for a LaTeX solution. This means no PNG

user2763361
  • 3,789
  • 11
  • 45
  • 81

2 Answers2

1

Use png like:

\begin{figure}
\begin{center}
<<label, fig=FALSE>>=
png('label.png')
plot(rnorm(100000))
dev.off()
@
\end{center}
\includegraphics{label}
\caption{Visualisation in Sweave which can lag computers}
\end{figure}

Or use the Sweave driver from here.

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
1

An alternative (not a direct answer to the question asked) is to replace a scatterplot with large numbers of points with a hexagonal binning plot instead. The hexbin package (bioconductor) or the ggplot2 package both have functions for creating the hexagonal binning plots. These plots will be smaller/faster than a scatterplot that contains many points, and for that many points the hexbin plot may even be more meaningful.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110