Skip to content

saving graphs; jpeg(), bitmap()

6 messages · Tiago R Magalhaes, Rob Goedman, stefano iacus +2 more

#
Dear Mac R-users

I want to export some plots. I have looked in the documentation and 
in the R-help archives. 2 main functions jpeg(), bitmap() are used, 
but I can't save any plots using them. (error logs at the end of the 
email). I'm using a PowerBook G4, Panther 10.3, R.2.1.

a) when using jpeg() I seem to be missing the X11 server. I have X11 
on my computer and it works fine. (XDarwin 1.3b4). On the R menu, 
under Miscillaneous there is a Run X11 server. When I lauch it 
reports an error:  "2004-12-08 22:24:13.082 open[10513] Couldn't 
launch application:  X11.app"

b) for using bitmap() I don't have the ghostscript file. Is it a mac 
file? Should I get it from somewhere?

c) I saved the files from the quartz device with the menu function. 
This solves the problem somewhat, but: I would like to save jpeg 
files. Even if I save pdf I would like to write it in a script. 
pdf() should do it, but I can only produce files with zero bytes 
using it...

d) and this is really just curiosity. The pdf file exported via menu 
is small (16kb) but when I open it in Photoshop and tell it to be 
300dpi becomes a big file (14Mb) and the quality is very good! I 
imagine this to be related to vectors instead of dots. I googled the 
terms, but there's nothing that mention pdfs as good grahp formats (I 
didn't do an extensive search, there were MANY documents, even trying 
to be very stringent)

#####################
errors
jpeg('pic1.jpg')
Error in X11(paste("jpeg::", quality, ":", filename, sep = ""), width,  :
	unable to start device JPEG
In addition: Warning message:
unable to open connection to X11 display`'

bitmap('temp.jpg', type='jpeg', res='300')
/bin/sh: line 1: gs: command not found
Error in bitmap("temp.jpg", type = "jpeg", res = "300") :
	Sorry, gs cannot be found
#
Tiago,
On Dec 8, 2004, at 2:50 PM, Tiago R Magalhaes wrote:

            
Below an example of how I use jpeg. Make sure you start X11, either 
from R Console toolbar,
from Finder or the dock (you can close the X11 command window but *not 
*X11 - i.e. notice
the little black triangle if X11 is in your dock):

jpeg(file="./Books/Good/l1lsat.jpg")
op <- par(mfrow=c(1, 2))	# 1 row, 2 plots in this example
hist(rnorm(100))
boxplot(rnorm(25) , horizontal=T)
par(op)	# reset to previous par() settings
dev.off()

Let me know if this works,
Rob
#
Hi Tiago,
you need to run the X11 server first indeed.
Close R and try just to launch X11 from its icon.
If it doesn't launch, please have a look at the Console Application 
window to see what's happening. Let us know.
stefano
On Dec 8, 2004, at 11:50 PM, Tiago R Magalhaes wrote:

            
#
Hi Tiago,
On Dec 8, 2004, at 5:50 PM, Tiago R Magalhaes wrote:

            
Um... why do you use XDarwin instead of the supported Apple X11 which 
comes with Mac OS X? The GUI (i.e. that button) is designed to work 
with Apple's X11, because it's the official standard (you don't even 
have to download it..). Last time I saw XDarwin its WM were much less 
well integrated that quartz-wm...

You can still use XDarwin if you feel like it, but in any case make 
sure your DISPLAY is set - if in doubt, type
Sys.setenv(DISPLAY=":0.0")
in R before using those graphics devices.
gs is basically a program running on most platforms, including Mac - if 
you use TeX then you should have gs already installed (or you can get 
it via i-Installer along with the TeX stuff).
PDF is actually a very good format supporting both bitmap (cf 
PhotoShop) and vector graphics (cf Illustrator) - it's even better than 
old PostScript, because it supports transparency and other cool things. 
Mac OS X actually uses PDF as its main display format. In fact PS used 
to be the standard for publishing and nowadays PDF is replacing that 
role. As a Mac user you're in the fortunate position of having many 
good PDF tools at your fingertips (in contrast to the Win folks :P).

Cheers,
Simon
#
On Dec 9, 2004, at 1:00 AM, Simon Urbanek wrote:

            
Tiago, Simon is right. You should probably use Apple X11 or set the 
DISPLAY var on your own.
well, let me say that the PDF file saved via R menus on mac, makes a 
copy of the current graphic device (quartz) on the R pdf() device. It's 
order of magnitude smaller that what you get by using quartz (but don't 
ask me why, I simply don't have to check at the moment).
stefano
#
On Dec 8, 2004, at 4:05 PM, stefano iacus wrote:

            
There's not much we can do about the Quartz file sizes---Quartz doesn't 
do much compression and includes a lot of redundant 
information---either for safety reasons or size/speed tradeoff. There 
are a couple of post-processing tools that can shrink Quartz PDFs, but 
who knows. Rumor has it that Tiger's PDFKit may help with that.
---
Byron Ellis (ellis@stat.harvard.edu)
"Oook" -- The Librarian