[R] mtext bug

Duncan Murdoch murdoch.duncan at gmail.com
Sun Jun 3 00:26:31 CEST 2012


On 12-06-02 6:21 PM, Matthew Johnson wrote:
> Sir,
>
> I have hit a the limits of my understanding of text / par / opar etc...
>
> I have a few related xts data frames which have multiple columns, and have
> written a for-loop to make a set of charts - however i do not get any
> margin text when i run the loop.
>
> when i test the code outside of the loop the margin text appears - however
> when i run the loop the margin text does not appear ... what gives?

You're calling par() before png().  Your par() settings will apply to 
the device that was active before you open the png() device, not to it.

Duncan Murdoch

>
> here is the code
>
> for (col in 1:ncol(xdf)){
>    par(mar=c(3.5, 4.5, 2, 1), oma=c(2,0,0,0))
>    ymin = min(xdf[,col]) - 20
>    ymax = max(xdf[,col]) + 20
>    png(paste(drive, names(xdf)[col], '.png', sep=""))
>    plot(coredata(yr09_10[,col]), type='l', ylim=c(ymin, ymax), col=1, lwd=2,
> las=1, xlab="", ylab="",
>         xaxt='n', main=names(xdf)[col])
>    lines(coredata(yr10_11[,col]), col=2, lwd=2)
>    lines(coredata(yr11_12[,col]), col=3, lwd=2)
>    axis(1, at=c(1:365), labels=format(index(yr09_10), "%d-%b"), tck=0.01,
> las=1)
>    legend("bottom", inset=0.02, title="Financial Years", c("09/10", "10/11",
> "11/12"), col=c(1,2,3), lwd=3, horiz=TRUE, bty='n')
>    mtext(stamp, cex=0.75, line=0, side=1, adj=1, outer=T)
>    mtext("Source: ABS", cex=0.75, side=1, adj=0, outer=T)
>    dev.off()
> }
>
> the charts are certainly re-made each time (i've checked this!) and they
> appear as desired, excepting the absence of the margin text.
>
> could anyone please help?
>
> tips on any other aspects of the above code are also very welcome.
>
> thanks and best regards
>
> matt johnson
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.



More information about the R-help mailing list