[R] plot scaling bug when using par(mfg)
Mark Cowley
m.cowley at garvan.org.au
Thu Apr 30 07:42:39 CEST 2009
Dear list,
I've noticed a width/height scaling bug in multi-panel plots when you
change the active plot using par mfg
The underlying par setting that maps the full plot width (or height)
to the numerical axis labels does not get updated when you change
plots with par(mfg=...). Thus plotting a point at c(10,10) in the
first plot will only be in the correct place IF the most recently
generated plot had the same x and y limits. This affects all plots
except the most recently created one.
The error is reproduced whether you set the plot up using:
par(mfcol=c(1,3)) -or- par(mfrow=c(1,3)) -or- layout(matrix(c(1,3),1,2))
I've tested this with 2x2, 1x2, 1x3 plots and all reproduce the error
Tested on R 2.8.0 on OSX and R 2.7.1 on WinXP and both reproduce the
error
See ### comments for the errors below.
cheers,
Mark
# draw 3 simple plots
par(mfcol=c(1,3))
plot(1:100, 1:100)
plot(1:200, 1:200)
plot(1:300, 1:300)
# add points to first plot which should span the whole plot
par(mfg=c(1,1))
points(1:100, 1:100, pch="x", col="red")
# you should only see one dotted line at 100
abline(v=c(100,200,300), h=c(100,200,300), lty=c("dotted", "dashed",
"solid"))
### instead you see 3 lines at 33, 66, 100
# add points to second plot which should span the whole plot
par(mfg=c(1,2))
points(1:200, 1:200, pch="x", col="red")
# you should see a dotted and dashed line at 100 and 200
abline(v=c(100,200,300), h=c(100,200,300), lty=c("dotted", "dashed",
"solid"))
### instead you see 3 lines at 66, 133, 200
# add points to third plot which should span the whole plot
par(mfg=c(1,3))
points(1:300, 1:300, pch="x", col="red")
abline(v=c(100,200,300), h=c(100,200,300), lty=c("dotted", "dashed",
"solid"))
### there are indeed 3 lines at 100, 200, 300
sessionInfo()
R version 2.8.0 (2008-10-20)
i386-apple-darwin8.11.1
locale:
en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] graphics grDevices datasets utils stats methods base
other attached packages:
[1] pwbc_0.1 mjcdev_0.1 tigrmev_0.1 slfa_0.1
sage_0.1
[6] qtlreaper_0.1 pajek_0.1 mjcstats_0.1 mjcspot_0.1
mjcgraphics_0.1
[11] mjcaffy_0.1 haselst_0.1 geomi_0.1 geo_0.1
genomics_0.1
[16] cor_0.1 bootstrap_0.1 blat_0.1 bitops_1.0-4
mjcbase_0.1
[21] gdata_2.4.2 gtools_2.5.0
-----------------------------------------------------
Mark Cowley, PhD
Peter Wills Bioinformatics Centre
Garvan Institute of Medical Research, Sydney, Australia
More information about the R-help
mailing list