我正在尝试使用ggforce包中的facet_grid_paginate在 R (v4.1.1) 降价中将绘图拆分到多个页面上。使用此代码:
```{r fc1_plots}
fc1Df <- cleanData %>%
filter(anom1 == "FC1")
fc1 <- ggplot(fc1Df, aes(x=TriggerIndex, y=Result)) +
geom_line(show.legend=FALSE) + ylim(0, max(fc1Df$Result) + 0.01) +
geom_hline(yintercept=0.04, size=0.5, color='red', linetype='dashed') +
xlab('Trigger Index') + ylab("Gap (mm)") +
ggtitle('Gap Measurements of Parts with FC1 Classifiation') +
facet_wrap_paginate(~PartID, nrow=4, ncol=2, scales="free_y", shrink = FALSE)
required_n_pages <- n_pages(fc1)
for(i in 1:required_n_pages) {
p <- ggplot(fc1Df, aes(x=TriggerIndex, y=Result)) +
geom_line(show.legend=FALSE) +
geom_hline(yintercept=0.04, size=0.5, color='red', linetype='dashed') +
xlab('Trigger Index') + ylab("Gap (mm)") +
ggtitle('Gap Measurements of Parts with FC1 Classification') +
facet_wrap_paginate(~PartID, nrow=4, ncol=2, scales = "free_y", shrink = FALSE, page=i)
print(p)
}
结果是正确的分页符,但绘图只占页面的大约 1/2。这是结果页面的图像:
如您所见,绘图仅占页面的一半。我希望这些情节占据整个页面。所以,我尝试添加fig.height = 10
到块选项,但得到了这个结果:
高度看起来好多了,但现在我得到额外的图溢出页面的右侧。所以,我的问题是:如何让分面网格使用整页的 4 x 2 绘图分割到多个页面?