[R] Inserting a plot into another
Greg Snow
Greg.Snow at imail.org
Mon Oct 4 19:24:24 CEST 2010
OK, I found the bug in subplot (it was never tested with multiple figures). The bug has been fixed, but probably won't make it to CRAN any time soon. In the meantime there are a couple of work arounds.
1. create your own local copy of subplot and edit it so that the 1st 3 lines of the body are:
type <- match.arg(type)
old.par <- par( c(type, 'usr', names(pars) ) )
on.exit(par(old.par))
(this means moving the 'type <-' line and modifying the 'old.par <-' line ).
Then use this copy instead of the one in TeachingDemos.
2. The problem comes because par('mfg') is getting updated by subplot when it shouldn't be, you can just set par(mfg= ) yourself after each call to subplot.
3. wait a couple of days for the R-forge version to be updated, then install the R-forge version of TeachingDemos 2.8.
Sorry for the problems and hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Filoche
> Sent: Monday, October 04, 2010 7:58 AM
> To: r-help at r-project.org
> Subject: Re: [R] Inserting a plot into another
>
>
> Hi everyone.
>
> First, thank you for your answers, it helped me alot.
>
> I have 1 more question regarding subplot. I'm using this function in a
> graph that contains 6 plots (3 x 2). This is producing strange
> behavior.
> http://img545.imageshack.us/img545/9233/fig6.png See here for the
> resulting
> figure.
>
> For instance here's my code :
>
> pdf(file="C:/Users/Modelisation/Desktop/Fig6.pdf", width = 8.5, height
> = 11,
> pointsize = 12);
>
> par(mfcol = c(3,2), mai = c(0.7,0.8,0,0), omi = c(1, 0, 0.7, 0.1));
>
> plot(FSL.data_Center$Distance, 4.6/FSL.data_Center$kd.BLUE., pch = 22,
> bg =
> "gray43", xlab = "Distance (km)", ylab = "1% penetration depth (m) ",
> ylim =
> c(0,20), xaxt = "n", yaxt = "n", xpd = NA);
> axis(1, at = c(100,200,300,400,500),labels = c(100,200,300,400,500),
> cex.axis=1, tck = 0.02);
> axis(2, tck = 0.02);
>
> ...
>
> #Subplots
> subplot(plot(lowess(FSL.data_North$Distance,
> 4.6/FSL.data_North$kd.BLUE.),
> type = 'l', xlab = "", ylab = "", cex.axis = 0.75, xlim = c(0,450),
> ylim =
> c(0,20)), 330,17, size = c(.96, .6));
> subplot(plot(lowess(FSL.data_Center$Distance,
> 4.6/FSL.data_Center$kd.RED.),
> type = 'l', xlab = "", ylab = "", cex.axis = 0.75, xlim = c(0,450),
> ylim =
> c(0,20)), 330,17, size = c(.96, .6));
> subplot(plot(lowess(FSL.data_South$Distance,
> 4.6/FSL.data_South$kd.GREEN.),
> type = 'l', xlab = "", ylab = "", cex.axis = 0.75, xlim = c(0,450),
> ylim =
> c(0,20)), 330,17, size = c(.96, .6));
>
> PLOT CODE FOR THE 5 OTHER FIGURES HERE
>
> dev.off();
>
> The last 2 subplots are plotted in at the bottom of the page. I would
> like
> to have the last 2 curves on the plot A.
>
> With regards,
> Phil
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Inserting-
> a-plot-into-another-tp2720936p2954362.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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