[R] Adding text to both grid and base graphs
Rik Schoemaker
RikSchoemaker at zonnet.nl
Mon Mar 9 16:51:43 CET 2009
Dear Richie,
Unfortunately that doesn't help because it requires you to know beforehand
what sort of graph you're generating. I want to be able to generate a graph
(irrespective of the type) and then use a common process to label them so I
don't have to think about which way I generated the graph to start with...
Cheers,
Rik
-----Original Message-----
From: Richard.Cotton at hsl.gov.uk [mailto:Richard.Cotton at hsl.gov.uk]
Sent: 09 March 2009 16:45
To: Rik Schoemaker
Cc: r-help at r-project.org; r-help-bounces at r-project.org
Subject: Re: [R] Adding text to both grid and base graphs
> 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