Quantcast

Inserting a plot into another

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Inserting a plot into another

Filoche
Hi everyone.

I would like to know if it was possible to insert a plot into another one. For example I have a plot and I would like to add a smaller plot in the top right corner.

Best regards,
Phil
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Inserting a plot into another

Greg Snow-2
Look at the subplot function in the TeachingDemos package.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Filoche
> Sent: Thursday, September 30, 2010 9:01 AM
> To: [hidden email]
> Subject: [R] Inserting a plot into another
>
>
> Hi everyone.
>
> I would like to know if it was possible to insert a plot into another
> one.
> For example I have a plot and I would like to add a smaller plot in the
> top
> right corner.
>
> Best regards,
> Phil
> --
> View this message in context: http://r.789695.n4.nabble.com/Inserting-
> a-plot-into-another-tp2720936p2720936.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Inserting a plot into another

Filoche
Ty sire.

I'll take a look at it.

With regards,
Phil
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Inserting a plot into another

Jim Lemon
In reply to this post by Filoche
On 10/01/2010 01:01 AM, Filoche wrote:
>
> Hi everyone.
>
> I would like to know if it was possible to insert a plot into another one.
> For example I have a plot and I would like to add a smaller plot in the top
> right corner.
>
Hi Phil,
Take a look at the subplot function in TeachingDemos.

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Inserting a plot into another

jamec9869
In reply to this post by Filoche
hi
I'll take a look at it.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Inserting a plot into another

Filoche
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. 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Inserting a plot into another

Greg Snow-2
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
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Filoche
> Sent: Monday, October 04, 2010 7:58 AM
> To: [hidden email]
> 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Inserting a plot into another

Filoche
Hi Greg.

Thank you for the time you took to look at my problem.

I'll try your solution until CRAN is updated.

With regards,
Phil
Loading...