[R] Adding text to both grid and base graphs
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Mon Mar 9 16:44:42 CET 2009
> I generate graphs using both the grid system (with lattice) and the base
> system. I'd like to be able to identify these graphs later on with a bit
of
> identifying text (e.g. a date and some comments). Adding text to these
> graphs cannot be done using a common system if you want to save them as
emf
> files. I now use:
>
> mtext("labelling
> text",outer=TRUE,at=0.5,adj=0.5,line=-1.1,side=1,cex=0.7,col="darkgrey")
>
> for base graphs and
>
> grid.text("labelling
text",x=0.5,y=0.005,just="bottom",gp=gpar(fontsize=8,
> col="darkgrey"))
>
> for grid graphs.
>
> Unfortunately if I were to use mtext on a grid graph and copy to emf, I
get
> the error:
> Error in dev.copy(win.metafile, pltfile) : invalid graphics state
>
> Is there a way to detect the current graphics state so I can choose
which
> command to give automatically? (or is there an easier way to go about
this?)
The easier way: use win.metafile to save your plots, e.g.
win.metafile("base.emf")
plot(runif(50))
mtext("labelling
text",outer=TRUE,at=0.5,adj=0.5,line=-1.1,side=1,cex=0.7,col="darkgrey")
dev.off()
win.metafile("grid.emf")
xyplot(runif(50)~1:50)
grid.text("labelling text",x=0.5,y=0.005,just="bottom",gp=gpar(fontsize=8,
col="darkgrey"))
dev.off()
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}
More information about the R-help
mailing list