[R] show and produce PDF file with pdf() and dev.off( ) in function

mlell08 mlell08 at googlemail.com
Sat Mar 24 13:04:56 CET 2012


you could either define a plotting function which passes your arguments
to plot() two times, with different devices active.
this function plots the given arguments two times:
 pl<- function(...){
   X11()                   #or pdf()
   plot(...)
   # dev.off()  if pdf() is used
   X11()                  # open second graphics device
   plot(...)
}

pl(1:10,pch=10)
 
or you make a function evaluate your plotting arguments two times if
you're using other plotting functions like lines(), points(), abline()
etc. In this case you have to escape your plotting code with
expression() so it is only executed when you explicitly demand it by
using eval()

Best regards!

plEval <- function(e){
  X11()
  eval(e)
  X11()
  eval(e)
}

plEval(
 expression({
  plot(1:10,pch=5)
  abline(h=3,col="red")
 })
)



More information about the R-help mailing list