Einar Árnason
2009-Apr-05 12:29 UTC
[R] problem with lattice tiff or bitmap: character size and color
Hi all, I am trying to make tiff files of lattice plots at a resolution greater than 300 dpi required by a journal (PLoS ONE). I have tried both the tiff and bitmap functions. tiff keeps panel colors but reduces axes and tick labels so they are nearly invisible. bitmap maintains correct label size but only produces greyscale. Regular plots work fine with tiff; the problem is only with lattice plots. How can I keep the right sizes using tiff or, alternatively, how can I get bitmap to produce colors? I have made this test function using an xyplot example to demonstrate the problem. `test` <- function(tiff=F, bitmap=F) { ### requires states ### states <- data.frame(state.x77, state.name = dimnames(state.x77)[[1]], ### state.region = state.region) if(bitmap) bitmap("bitmaptest.tiff", width=17.15, height=17.15, units="cm", res=1200, pointsize=10, type="tifflzw",bg="white") if(tiff) tiff(file="tifftest.tiff",width=17.15,height=17.15,units="cm", res=1200, pointsize=10, compression = "lzw") ### tiff(file="tifftest.tiff",width=17.15,height=17.15,units="cm", ###res=72, pointsize=10, compression = "lzw") plot(xyplot(Murder ~ Population | state.region, data = states, groups = state.name, panel = function(x, y, subscripts, groups) ltext(x = x, y = y, label = groups[subscripts], cex=0.5, fontfamily = "HersheySans"))) if(bitmap) dev.off() if(tiff) dev.off() }> R.Version()$platform [1] "x86_64-redhat-linux-gnu" $arch [1] "x86_64" $os [1] "linux-gnu" $system [1] "x86_64, linux-gnu" $status [1] "" $major [1] "2" $minor [1] "8.1" $year [1] "2008" $month [1] "12" $day [1] "22" $`svn rev` [1] "47281" $language [1] "R" $version.string [1] "R version 2.8.1 (2008-12-22)"
Einar Árnason
2009-Apr-07 13:36 UTC
[R] problem with lattice tiff or bitmap: character size and color
Thank you Professor Brian Ripley for very helpful comments. Using type="tiff24nc" in bitmap mostly solved my problems. However, some complicated figures still come out in greyscale with bitmap even when using type="tiff24nc". The tiff function preserves the color but reduces the character size as before. The good news is that dev2bitmap from X11 gives the correct figure. The newtest function below demonstrates this behavior. I do have the latest R for my system (R-core-2.8.1-8.fc10.x86_64). Another question, is it possible to use lzw compression other than type"tifflzw"? (the figures I produced with type="tiff24nc" are about 200 Mb. When opened and saved in photoshop with lzw compression they become about 2 Mb). Thank you Regards Einar Arnason> newtest(bitmap=T) # produces greyscale > newtest(tiff=T) # produces color with tiny characters > X11() > newtest() > dev2bitmap("dev2bitmaptest.tiff", width=17.15, height=17.15, units="cm",res=1200, pointsize=10, type="tiff24nc",bg="white") # produces required figure `newtest` <- function(tiff=F, bitmap=F) { ### requires states ### states <- data.frame(state.x77, state.name = dimnames(state.x77)[[1]], state.region = state.region) if(bitmap) bitmap("bitmaptest.tiff", width=17.15, height=17.15, units="cm", res=1200, pointsize=10, type="tiff24nc",bg="white") if(tiff) tiff(file="tifftest.tiff",width=17.15,height=17.15,units="cm", res=1200, pointsize=10, compression = "lzw") ### tiff(file="tifftest.tiff",width=17.15,height=17.15,units="cm", res=72, pointsize=10, compression = "lzw") foo <- xyplot(Murder ~ Population | state.region, data = states, groups = state.name, panel = function(x, y, subscripts, groups) ltext(x = x, y = y, label = groups[subscripts], cex=0.5, fontfamily = "HersheySans")) plot(foo,position=c(0,0,0.33,1)) plot(foo,position=c(0.33,0,0.66,1), newpage=FALSE) plot(foo,position=c(0.66,0,0.99,1), newpage=FALSE) if(bitmap) dev.off() if(tiff) dev.off() }> You needed to update your R (see the posting guide). From the BUG > FIXES for 2.8.1 patched: > > o grid-based plots no longer reset the base text size to the > default 96dpi in cairo-based bitmap devices. > > Lattice plots are based on grid, and (probably) you are using the > cairo-based bitmap device. > > On Sun, 5 Apr 2009, Einar ?rnason wrote: > >> Hi all, >> >> I am trying to make tiff files of lattice plots at a resolution greater >> than 300 dpi required by a journal (PLoS ONE). I have tried both the >> tiff >> and bitmap functions. tiff keeps panel colors but reduces axes and tick >> labels so they are nearly invisible. bitmap maintains correct label size >> but only produces greyscale. Regular plots work fine with tiff; the >> problem is only with lattice plots. >> >> How can I keep the right sizes using tiff or, alternatively, how can I >> get >> bitmap to produce colors? > > Use the correct device type, e.g. tiff24nc (24 bit RGB). tifflzw is > black-and-white (see your ghostscript documentation). > >> I have made this test function using an xyplot example to demonstrate >> the >> problem. >> >> `test` <- function(tiff=F, bitmap=F) >> { >> ### requires states >> ### states <- data.frame(state.x77, state.name >> dimnames(state.x77)[[1]], >> ### state.region = state.region) >> if(bitmap) >> bitmap("bitmaptest.tiff", width=17.15, height=17.15, units="cm", >> res=1200, pointsize=10, type="tifflzw",bg="white") >> if(tiff) >> tiff(file="tifftest.tiff",width=17.15,height=17.15,units="cm", >> res=1200, pointsize=10, compression = "lzw") >> ### tiff(file="tifftest.tiff",width=17.15,height=17.15,units="cm", >> ###res=72, pointsize=10, compression = "lzw") >> plot(xyplot(Murder ~ Population | state.region, data = states, >> groups = state.name, >> panel = function(x, y, subscripts, groups) >> ltext(x = x, y = y, label = groups[subscripts], cex=0.5, >> fontfamily = "HersheySans"))) >> if(bitmap) >> dev.off() >> if(tiff) >> dev.off() >> } >> >> >>> R.Version() >> $platform >> [1] "x86_64-redhat-linux-gnu" >> >> $arch >> [1] "x86_64" >> >> $os >> [1] "linux-gnu" >> >> $system >> [1] "x86_64, linux-gnu" >> >> $status >> [1] "" >> >> $major >> [1] "2" >> >> $minor >> [1] "8.1" >> >> $year >> [1] "2008" >> >> $month >> [1] "12" >> >> $day >> [1] "22" >> >> $`svn rev` >> [1] "47281" >> >> $language >> [1] "R" >> >> $version.string >> [1] "R version 2.8.1 (2008-12-22)" >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > -- > Brian D. Ripley, ripley at stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UK Fax: +44 1865 272595