Skip to content

little subplot in corner

7 messages · Thomas Steiner, Greg Snow, Henrique Dallazuanna

#
I want to draw a little subplot ("overview") into my detailed plot. It
should be placed in say the top right corner and have the size of some
legend (like legend(x="topright", inset=0.03, ...)

#main plot
plot(rnorm(100))
#give little density in corner
plot(seq(-2,2,length=300),dnorm(seq(-2,2,length=300)),type="l")

I don't want something like par(mfrow=c(1,2)) as this gives subplots
of equal size.
I saw that gridBase is very flexible, but could not find a suitable example.

Thanks for help,
Thomas
#
I don't if is this what you want, but:

plot(rnorm(100))
par(fig=c(0, 1/2, 0, 1/2), new=T)
plot(seq(-2,2,length=300),dnorm(seq(-2,2,length=300)),type="l", axes =
F, xlab="", ylab="")
On 20/03/2008, Thomas Steiner <finbref.2006 at gmail.com> wrote:

  
    
#
Look at the subplot function in the TeachingDemos package (the
cnvrt.coords function in the same package can be used to help in finding
coordinates to place the plot).

Hope this helps,
3 days later
#
Henrique,

Although your solution is perfect, I had later a problem with setting
the background. Perhaps you know how to get this as well:

set.seed(24032008)
plot(rnorm(10),type="l",col="red")
grid()
front=c(0.5, .97, 0.5, .97)
par(fig=front, new=T)#, bg="skyblue" does not work
rec=c(par("usr")[1]+(par("usr")[2]-par("usr")[1])*front[1],
par("usr")[3]+(par("usr")[4]-par("usr")[3])*front[3],
par("usr")[1]+(par("usr")[2]-par("usr")[1])*front[3],
par("usr")[1]+(par("usr")[2]-par("usr")[1])*front[4])
#rect(rec[1],rec[2],rec[3],rec[4],col="yellow")
plot(rnorm(4),type="l",col="blue",xlab="",ylab="")

as you can see it would be good to be able to set the background of
the subfigure. as the par(bg=) does not work, I tried to plot a
rectangle. Just uncomment the send-last line and you will see that the
original plot disappears after some strange rectangle is drawn.

If you have any idea again, it would be evry much appreaciated to let me know.
Thomas

PS: to see my first attempts, look at
http://commons.wikimedia.org/wiki/Image:Eurusd-id.png
#
Perhaps:

set.seed(24032008)
plot(rnorm(10),type="l",col="red")
grid()
front=c(0.5, .97, 0.5, .97)
par(fig=front, new=T)#, bg="skyblue" does not work
set.seed(24032008)
x <- rnorm(4)
plot(x,type="l",col="blue",xlab="",ylab="", bg="yellow")
rect(par("usr")[1], par("usr")[3], par("usr")[2], par("usr")[4], col="yellow")
lines(x, col="blue")
On 24/03/2008, Thomas Steiner <finbref.2006 at gmail.com> wrote:

  
    
#
Wonderful, thanks a lot.
I just have to call the plot first and then the rect (and then I can
plot it again)... %D
Have a nice day,
Thomas