[R] mtext in the top left of margin
Adams, Jean
jvadams at usgs.gov
Wed Sep 16 20:04:15 CEST 2015
You can use the coordinates of the plot region as fractions of the figure
region, par("plt"), to define the adj= argument of mtext(). And you can
use the number of lines of the plot margin to define the line= argument of
mtext(). For example:
plot.figure <- function() {
par(mfrow=c(3, 1), mar=c(3, 5, 3, 2), oma=c(1, 1, 1, 1))
# use the coords of the plot region as fractions of the figure region
# to define the adj= argument of mtext()
pplt <- par("plt")
adjx <- (0 - pplt[1]) / (pplt[2] - pplt[1])
# use the number of lines of margin to define the line= argument of
mtext()
liney <- par("mar")[3] - 1.5
plot(dnorm, from=-4, to=4, main="Test")
box("plot", col="grey")
box("figure", col="red")
mtext("A", side=3, adj=adjx, line=liney)
plot(dnorm, from=-4, to=4)
box("plot", col="grey")
box("figure", col="red")
mtext("B", side=3, adj=adjx, line=liney)
plot(dnorm, from=-4, to=4)
box("plot", col="grey")
box("figure", col="red")
mtext("C", side=3, adj=adjx, line=liney)
box("outer", col="blue")
}
plot.figure()
Jean
On Wed, Sep 16, 2015 at 5:00 AM, Hermann Norpois <hnorpois at gmail.com> wrote:
> Hello,
>
> for a multiple figures plot I am looking for the syntax to put text in the
> top left of the margin (of the plot). I want my testfunction plot.figure to
> place mtext in the top left of the red margin (created by box("figure",
> col="red")).
>
> Can anybody help?
>
> Thanks
> Hermann
>
> plot.figure <- function ()
> {
>
>
> par (mfrow=c(3,1))
> par (mar=c(3,3,1,0.5))
> par (oma=c(1,1,1,1))
> par (mar=c(3,5,3,2))
>
> plot (dnorm, from=-4, to=4, main="Test")
> box ("plot", col="grey")
> box ("figure", col="red")
> box ("outer", col="blue")
> mtext ("A", side=3, adj=0, line=1.5)
>
> plot (dnorm, from=-4, to=4)
> box ("plot", col="grey")
> box ("figure", col="red")
> box ("outer", col="blue")
> mtext ("B", side=3, adj=0, line=1)
> plot (dnorm, from=-4, to=4)
> box ("plot", col="grey")
> box ("figure", col="red")
> box ("outer", col="blue")
> mtext ("C", side=3, adj=0)
> }
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list