[R] Color eps/ps output from specialized plots?

Deepayan Sarkar deepayan.sarkar at gmail.com
Mon Oct 23 23:43:18 CEST 2006


On 10/23/06, Turgut Durduran <durduran at yahoo.com> wrote:
> Hello,
>
> First a disclaimer :) I am very new to using R.
>
> I am generating some plots and eventhough I can get colored output in the encapsulated postscript files in the simplest of commands (e.g. plot(1:10,1:10, type="l", col="red") ), it does not work for the particular plots I want. It works on the screen.
>
> Here is an example taken out from "Mixed-Effects Models in S and S-Plus by Pinheiro and Bates";
>
> library(nlme)
> plot(CO2)
> postscript("tmp.eps")
> plot(CO2)
> dev.off()

You are seeing the results of what was, in hindsight, an unfortunate
design decision in nlme. Since the "plot" function in R is generic,
not all plot() calls are guaranteed to behave the same way. In
particular, the (several) plot() functions in nlme don't actually plot
anything, instead they return an object of class "trellis", which
themselves need to be 'plot'ted or 'print'ed to see any output.

Now, this is not normally a problem, but it is when you run your code
through source (which I presume you are, although you have neglected
to mention it). The solution is to replace the

plot(CO2)

command by either

print(plot(CO2))

or the even odder

plot(plot(CO2))

See

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

for a relevant discussion.

-Deepayan



More information about the R-help mailing list