tags:

views:

284

answers:

2

I have a large chart with many data points. When I create the qplot in R, the chart is auto-fitted to the window. Even if I maximize the window, the chart is still too small and details are lost. I would like to save it as a large PNG and then look at certain areas at 1:1 resolution with an image viewer (as I cannot zoom in easily in R). Rendering the chart for a range of the values is not really convenient, I'd like to have one PNG and scroll around and discuss it with my peers, rather than pre-generating a bunch of subgraphs.

Is this possible? I kind of expect to be so, but some help would be appreciated (I've recently started with R so am still finding my way around).

Thank you.

+4  A: 

One way would be:

myfile <- tempfile()                   # portable across OSs
pdf(file=myfile, height=20, width=20)  # 20x20 inches, adjust at will
plot(....)                             # or print(....) for lattice + ggplot2
dev.off()                              # finalize and close file
cat("Look at", myfile, "\n")

and now inspect the chart in the temp. file just created with a proper pdf viewer allowing you to zoom at will.

Dirk Eddelbuettel
Thanks. This did produce the PDF, found that Foxit is choking on the 22MB-file (at least after 5 minutes of 100% CPU is was still processing it). I'll give it more time.Is it possible to output not to a PDF but to a PNG? Graphics viewers handle large files with more ease. If not, I can live with this solution. From another question (http://stackoverflow.com/questions/2367328/how-to-change-current-plot-window-size-in-r) I learned about `dev.new` so I'll play with that one as well.Thanks again.
wishihadabettername
If you want to scale and zoom then you don't want to lossy format like png.
Dirk Eddelbuettel
PNG is not lossy, I guess you're thinking of JPGs. See http://en.wikipedia.org/wiki/Portable_Network_Graphics
wishihadabettername
Bad term on my part -- but it is bit-mapped. You want vector-based, hence pdf. Else you loose resolution.
Dirk Eddelbuettel
To use PNGs png(myfile, width=2000, height=2000) ## dimensions in pixelsWith a high enough res, PNGs work well for printing.
Eduardo Leoni
Dirk and Eduardo, thanks both for the tips. Both approaches work for me.
wishihadabettername
+3  A: 

Check out this previous question and the answers:

Basically, you can use the Cairo package to create svg files, which are vector based, not pixel based, I can then edit these in Inkscape and i think you can view them direct in firefox (???).

library(Cairo)
Cairo(600,600,file="testplot.svg",type="svg",bg="transparent",pointsize=8, units="px",dpi=400)
testplot
dev.off()
Cairo(1200,1200,file="testplot12200.png",type="png",bg="transparent",pointsize=12, units="px",dpi=200)
testplot
dev.off()

Now I had to play around with the various settings to get my plot as good as it can be before writing the file. (critical settings seem to be the pointsize, which varies the size of the points on the graph, the size, obviously, and the dpi)

PaulHurleyuk
Thanks, I'll try it today.
wishihadabettername