Skip to content

Problem with colormodel in pdf driver

9 messages · Luis Torgo, David Winsemius, Jorge Ivan Velez +2 more

#
I'm trying to create figures in PDF that use the 'gray' colormodel 
instead of the default 'RGB' model, by requirements of a publisher.

My problem has to do with the fact that I'm not being able to get gray 
colors with this option on the pdf() driver. Here is a small example for 
problem replication:

 > R.version
               _                          
platform       i486-pc-linux-gnu          
arch           i486                       
os             linux-gnu                  
system         i486, linux-gnu            
status                                    
major          2                          
minor          8.1                        
year           2008                       
month          12                         
day            22                         
svn rev        47281                      
language       R                          
version.string R version 2.8.1 (2008-12-22)

 > pdf('exp.pdf',colormodel='gray')
 > barplot(table(subset(iris,Petal.Width>1)$Species))
 > dev.off()

Contrary to what I was expecting the bars appear in black and not gray 
as they are supposed to. This is not particularly serious for this toy 
graph but for others it creates more problems.

Interesting enough this problem does not occur with the same option on 
the postscript() driver as it can be observed by running:
 > postscript('exp.eps',colormodel='gray')
 > barplot(table(subset(iris,Petal.Width>1)$Species))
 > dev.off()

Any help is most appreciated.

Luis Torgo
#
Try changing the color to "grey".

Despite the help pages saying this:
colormodel
a character string describing the color model: currently allowed  
values are "rgb", "gray" and "cmyk". Defaults to "rgb".

I got the expected behavior by making the "gray" -> "grey" change on  
my Mac OS 10.5.6/R2.8.1 system.
#
'gray' is what is in the code: 'grey' uses rgb -- just look at the pdf 
produced.

The issue is that the wrong ('stroke' not 'fill') colour is set in ht 
'gray' colormodel.
On Fri, 23 Jan 2009, David Winsemius wrote:

            

  
    
#
You may want to consider a dotchart instead of a barplot.  Then you can distinguish between groups by using symbols, grouping, and labels rather than depending on colors/shades of grey.
2 days later
#
Greg Snow wrote:
Thanks Greg. The only problem is that I was trying to illustrate the use 
of barplot() ...

I guess for now I can always use the pdf() driver with the default RGB 
colormodel and then use command line tools (e.g. ImageMagick) to convert 
the resulting graphs to grayscale...

Thanks all for the help.

Luis
#
On Mon, 26 Jan 2009, Luis Torgo wrote:

            
You won't be able to convert PDF to PDF with ImageMagick (possible 
with a helper).
Or update your R, as the posting guide suggested.  It works in 
R-patched and R-devel.
#
Prof Brian Ripley wrote:
Well actually I can and it worked perfectly. Just did:
$> mogrify *.pdf -type Grayscale

and all my PDFs got changed from RGB to Grayscale. Maybe a problem with 
versions of ImageMagick.... mine is

$> mogrify -version
Version: ImageMagick 6.3.7 08/21/08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC
That's good news. I'll give it a try, thanks.
#
I've tried the patched version but I still have some problems with the 
colormodel.
My version

 > R.version
               _                                         
platform       x86_64-unknown-linux-gnu                  
arch           x86_64                                    
os             linux-gnu                                 
system         x86_64, linux-gnu                         
status         Patched                                   
major          2                                         
minor          8.1                                       
year           2009                                      
month          01                                        
day            24                                        
svn rev        47727                                     
language       R                                         
version.string R version 2.8.1 Patched (2009-01-24 r47727)

I've created the following graph:

pdf('fig8_6.pdf',colormodel='gray')
barplot(table(subset(iris,Petal.Width>1)$Species))
dev.off()

The file "fig8_6.pdf" was then compiled into a document with pdflatex.

My publisher is "complaining" that the figure is not grayscale. He 
attached a picture that I also include in this email where he has used 
some software that allows him to exclude colors from the visualization. 
As it can be seen when including only Cyan, Magenta and Yellow there are 
still some parts of the figure that appear, whilst the rest of the book 
goes away...

Strangely enough all other figures of the book, which were created with 
the non-patched version of R (R version 2.8.1 (2008-12-22)), using 
exactly the same call to the pdf driver, do not have this "problem".


Any help is welcome.

Luis Torgo