After par (fig.), The text in the fields is not written

After setting graphical parameters using par(fig) and resetting them with the initial parameters, the text in the graph fields is not recorded. Only after executing another low level command inside the charting area will it work again. Here is an example:

 dev.off() plot(1:10) op <- par(no.readonly = TRUE) mtext("hello", adj=1, col=2) # written as expected par(fig=c(0.1,0.6,0.5,0.8), new=TRUE) par(op) mtext("hello ", adj=1, col=3) # not written mtext("hello ", adj=1, col=3, line=-1) # works inside plot region mtext("hello ", adj=1, col=3) # still not written text(50,20,"") # or abline # do something inside plot region mtext("hello ", adj=1, col=3) # now it works! 

This may be due to another question that I posted under after par (Fig.), Mtext is a bit disabled .

In addition, mtext , axis also does not work. In addition, text/abline/points , title(main="dummy") also solves the problem.

Could this be an R error? Or am I missing something?

+5
source share
1 answer

Through trial and error, it boils down to par(mfg=c(1, 1, 1, 1)) .

 plot(1:10) op <- par(no.readonly = TRUE) mtext("hello", adj=1, col=2) # written as expected par(op[names(op) == "mfg"]) mtext("bye ", adj=1, col=3) # not written mtext("hello ", adj=1, col=3, line=-1) # works inside plot region plot(1:10) op <- par(no.readonly = TRUE) mtext("hello", adj=1, col=2) # written as expected par(op[names(op) != "mfg"]) mtext("bye ", adj=1, col=3) # written as expected mtext("hello ", adj=1, col=3, line=-1) # works inside plot region 

I don’t understand why the installation of the figure, which will be built next, should disable the printing of text in the field (but not in the figure), and since mtext is implemented in C, it will take some effort to work.

+5
source

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


All Articles