After par (fig.), Mtext is slightly off

I am creating a subplot with a function that I called smallPlot . It sets par(fig) to the graph sub-region (or drawing for multi-channel graphs). However, after resetting the parameters, mtext slightly off. Any idea why this is happening?

 dev.off() plot(1:10) mtext("hello", adj=1, col=2) # written as expected op4 <- par(fig=c(0.1,0.8,0.3,0.8), new=TRUE) par(op4) mtext("hello ", adj=1, col=3) # right spot par(fig=c(0.1,0.8,0.3,0.8), new=TRUE) plot(rnorm(400), type="l") par(op4) mtext("hello ", adj=1, col=4) # too far left 

Edit: The original question was different, but easily resolved. Here it is for reference:

 dev.off() op1 <- par(no.readonly = TRUE) plot(1:10) abline(h=2, col=2) # drawn par(fig=c(0.1,0.8,0.3,0.8), new=TRUE) plot(rnorm(400), type="l") par(op1) abline(h=4, col=4) # not drawn! axis(4) 

Answer: op1$usr - 0,1,0,1 by default.

0
source share
1 answer

op4 does not have a usr element. After a small nested graph, usr changes. For reset, you can use something like this:

 dev.off() plot(1:10) usr <- par("usr") op4 <- par(fig=c(0.1,0.8,0.3,0.8), new=TRUE) plot(rnorm(400), type="l") par(op4) par(usr=usr) mtext("hello", adj=1, col=4); mtext("hello", adj=0, col=4) 
0
source

Source: https://habr.com/ru/post/1264579/


All Articles