小编Met*_*hic的帖子

在 R 中,如何使用引用列表中较早元素的某些元素构建列表?

我正在尝试做这样的事情:

opts = list(
  width=128,
  overlap=width/2,
)
Run Code Online (Sandbox Code Playgroud)

但是,正如预期的那样,我得到

Error: object 'width' not found
Run Code Online (Sandbox Code Playgroud)

挽救这个代码片段的好习惯是什么?

environment r list

6
推荐指数
1
解决办法
62
查看次数

使用arrangeGrob在叠加图中均衡ggplot2面板高度

我有两组时间序列数据,我想以堆叠的方式绘制.到目前为止,我已经能够得到这样的东西:

library(ggplot2);
library(gridExtra);

t=1:100; s=sin(t/10); c=cos(t/10);
g1=ggplot()+theme_bw()+geom_line(aes(x=t,y=s))+ylab(NULL)
g2=ggplot()+theme_bw()+geom_line(aes(x=t,y=c))+ylab("Cosine")+xlab("Time")

# get rid of the top plot's axis labels
g1=g1+theme(
  axis.text.x=element_blank(),
  panel.margin = unit(0,"null")
  );
g1=g1+labs(x=NULL);

# zero bottom margin of top plot
g1$theme$plot.margin[3]=unit(0,"null");

# zero top margin of bottom plot
g2$theme$plot.margin[1]=unit(0,"null");

# this trick equalizes the width of the two plot panels
g1g=ggplotGrob(g1);
g2g=ggplotGrob(g2);
g1g$widths=g2g$widths

# however, equalizing the heights of the panels is not so simple as
# the following:
# g1g$heights=g2g$heights

g=arrangeGrob(g1g,g2g)

plot(g)   #ggsave("out.svg",g,width=5,height=1.5);
Run Code Online (Sandbox Code Playgroud)

合并的图如下所示.我特别宽和短,以便您可以看到问题:arrangeGrob均衡绘图高度,但这样做会使绘图面板具有不同的高度.底部面板被底部图上的 …

r ggplot2 gridextra

2
推荐指数
1
解决办法
627
查看次数

标签 统计

r ×2

environment ×1

ggplot2 ×1

gridextra ×1

list ×1