绘制多个图形

时间:2014-04-22 07:23:36

标签: r plot

我想生成如下图:

enter image description here

这是一个展示"透析"和"翻译"一个叫做Wavelet的函数。这里的功能并不重要,但我是如何生成这样的情节的。

有人可以给我一个提示,这是最好的方法吗?如何获得图中的六个坐标轴?我应该从par(mfrow=c(3,3))开始吗?

到目前为止,我已使用以下代码进行了管理:

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

但它仍然不是我需要的

2 个答案:

答案 0 :(得分:1)

这是使用layout创建特定排列图的解决方案,左侧和上侧的长箭头的额外面板

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

答案 1 :(得分:0)

我会从这样的事情开始:

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

从这里开始使用一些主题格式

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

solution 2

相关问题