Zeljko Vrba
2009-Jun-01 06:19 UTC
[R] ggplot2: How to export several plots with same width?
I have three plots and I want the *plot area* to be of the same width on each plot. Since the three plots have different legends, the text width of the legend affects the width of the plot area (longer legend text narrower plot area). Exporting the three figures to postscript device of same size gives thus unequal plot areas. How can I calculate the correct width of postscript device for each figure, so that plot areas will be equally wide? Is there a better alternative? (I tried to place the legend inside the plot area, which kinda works, but the problem is that legend.position is relative to the *device*, not to the *plot area*, so I don' know how to align the legend with plot border.)
baptiste auguie
2009-Jun-01 08:01 UTC
[R] ggplot2: How to export several plots with same width?
I'm not sure it's currently possible with ggplot2 (lattice and latticeExtra offer some workarounds for this). Perhaps you can try this, http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-ggplot2:sharelegend (neater here: ) http://learnr.wordpress.com/2009/05/26/ggplot2-two-or-more-plots-sharing-the-same-legend/ except that in your case you'd have to place several legends. HTH, baptiste On 1 Jun 2009, at 08:19, Zeljko Vrba wrote:> I have three plots and I want the *plot area* to be of the same > width on > each plot. Since the three plots have different legends, the text > width > of the legend affects the width of the plot area (longer legend text > narrower plot area). Exporting the three figures to postscript device > of same size gives thus unequal plot areas. How can I calculate the > correct width of postscript device for each figure, so that plot areas > will be equally wide? > > Is there a better alternative? > > (I tried to place the legend inside the plot area, which kinda > works, but > the problem is that legend.position is relative to the *device*, not > to > the *plot area*, so I don' know how to align the legend with plot > border.) > > ______________________________________________ > 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.