1

I would like to generate a plot like the following:

enter image description here

This is a plot which demonstrates "dialation" and "translation" of a function called Wavelet. The function here is not important, but just how I can generate a plot like this.

Can someone give me a hint which is the best way to do it? How can I get the six coordinate axes like in the plot? Should I start with par(mfrow=c(3,3))?

Until now I have managed this with the following code:

mo<-function(t,trans=0,omega=6,j=0){
  dial<-2*2^(j*.125)
  sqrt((1/dial))*pi^(-1/4)*exp(1i*omega*((t-trans)/dial))*exp(-((t-trans)/dial)^2/2)
}

par(mfrow=c(3,3))

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=-3)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=0)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=3)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)


#############

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=-3,j=6)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=0,j=6)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=3,j=6)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)


#############

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=-3,j=6)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=0,j=6)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)

plot(seq(-10,10,length=1000),Re(mo(seq(-10,10,length=1000),trans=3,j=6)),axes=F,xlab="",ylab="",type="l")
abline(h=0,v=0)

enter image description here

But it is still not what I need

6
  • 1
    "I could probably do this myself, but would need too much time, which I do not have now" implies SO is a code writing service, which it is not. You may want to rephrase that. Commented Apr 22, 2014 at 7:25
  • Check out the fig option in par. It allows you to plot on some certain percentage of the region. In this case, you'd probably want to use mfrow = c(3, 3) on the bottom 80% (give or take) of the plot region. Commented Apr 22, 2014 at 7:41
  • I would definitely have a look at facet_wrap and facet_grid in ggplot2. These take care of a lot of the work with these kinds of multi-facet plots. Commented Apr 22, 2014 at 7:55
  • I have never used the package ggplot2 so it woul cost too much time... Commented Apr 22, 2014 at 7:56
  • What's wrong with your results? If the margins are too wide, adjust par(mar=c(...). Commented Apr 22, 2014 at 8:27

2 Answers 2

1

Here's a solution using layout to create a specific arrangement of plots, with extra panels for the long arrows on the left and top side

par(mar=c(1,1,1,1), oma=c(5,4,4,2))
m = matrix( c(0, 1, 1, 1,
              2, 3, 4, 5,
              2, 6, 7, 8, 
              2, 9, 10, 11),
        byrow=T, ncol=4)
l = layout(mat=m, widths=c(.1, .2, .2, .2), heights= c(.1, .2, .2, .2))

# check if the layout is as we expect
layout.show(l)

# add top arrow to panel 1
plot(1, xlim=c(1,10), ylim=c(0,1), type='n', axes=F, ann=F)
arrows(x0=1, x1=10, y0=0.5, y1=0.5)
mtext(side=3,'some text')
# add left arrow to panel 2
plot(1, xlim=c(0,1), ylim=c(1,10), type='n', axes=F, ann=F)
arrows(y0=10, y1=1, x0=0.5, x1=0.5)
mtext(side=2,'some text')

# add plots to panels 3:11
for (i in 1:9){

    curve(sin(x), -2*pi, 2*pi, axes=F, ann=F)

    # get x and y extents of plot for drawing arrows
    ymax = par('usr')[4]
    ymin = par('usr')[3]
    xmax = par('usr')[2]
    xmin = par('usr')[1]
    arrows(x0=0, y0=ymin, x1=0, y1=ymax, length=0.1)
    arrows(x0=xmin, y0=0, x1=xmax, y1=0, length=0.1)
}

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Look good! Maybe you have a suggestion how to add text to the overall-arrows like in my original one?
Use mtext, added to my post.
0

I would start with something like this:

fmo<-function(t,trans=0,omega=6,j=0){
  dial<-2*2^(j*.125)
  sqrt((1/dial))*pi^(-1/4)*exp(1i*omega*((t-trans)/dial))*exp(-((t-trans)/dial)^2/2)
}

dat <- expand.grid(x=seq(-10,10, length = 200),
               trans = c(-3,0,3), 
               j = c(0, 6, 12))
dat$g <- rep(1:9, each = 200)
dat$y <- with(dat, Re(fmo(t=x,trans=trans,omega=6,j=j)))

library(ggplot2)
ggplot(dat) + geom_line(aes(x=x, y=y)) + 
  facet_wrap(~g, ncol = 3)

ggplot solution 1

and work from here with some thematic formatting

ggplot(dat) + geom_line(aes(x=x, y=y)) + 
  geom_vline(aes(xintercept=0)) +
  facet_wrap(~g, ncol = 3) +
  theme_classic()

solution 2

2 Comments

Thanks for your suggestion! It looks nice, but the problem is, taht in your version the plots look like they were separate, but this is not the impression I would like to make. The wavelets are aplied to the same time series, in "translated" and "dilated" versions, in order to generate a two-dimensional decomposition.
@RStudent Sorry, I can't figure out what you mean. Any link to a known solution? It seems to me that you need a mixed approach, with some art editing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.