Reputation: 649
I seem to have some problems figuring out how at=...
in mtext(...)
functions.
If I plot some scatter plots with added text
df <- data.frame(x1=rnorm(20),x2=rnorm(20),x3=rnorm(20),x4=rnorm(20),x5=rnorm(20),x6=rnorm(20),x7=rnorm(20),x8=rnorm(20),x9=rnorm(20),x10=rnorm(20),x11=rnorm(20),x12=rnorm(20),x13=c(2,1,1,2,2,1,2,1,2,2,1,1,2,1,2,2,1,2,1,1))
par(mfrow=c(1,4))
plot(x1~x4,data=df);mtext(c("Scatter plot 1","Test"), at=c(1,1), line=c(0,1))
plot(x2~x3,data=df);mtext(c("Scatter plot 2","Test"), at=c(1,1), line=c(0,1))
plot(x5~x6,data=df);mtext(c("Scatter plot 3","Test"), at=c(1,1), line=c(0,1))
plot(x7~x8,data=df);mtext(c("Scatter plot 4","Test"), at=c(1,1), line=c(0,1))
I get something like
Why are the added texts being printed in dissimilar locations in respect to their plots? What makes at=c(1,1)
function differently with each plot? There seems to be no consistency in this pattern.
Upvotes: 0
Views: 49
Reputation: 24074
You can read in ?mtext
:
at: give location of each string in user coordinates. If the component of at corresponding to a particular text item is not a finite value (the default), the location will be determined by adj
So you can put at=Inf
and adjust the place with adj
, it will work as if your x-axis
went from 0
to 1
.
For example, you can try:
plot(0:10, 0:10)
mtext(side=1, line=0, at=Inf, "text 1", adj=0.9)
mtext(side=1, line=0, at=Inf, "text 1", adj=0.3)
Upvotes: 1