我正在尝试在 ar notebook 块中执行一个 for 循环来打印一些消息和交错的绘图,如下面的代码所示:
for(i in 1:2) {
print(paste0("before ", i))
plot(i, i)
print(paste0("after ", i))
}
但是,第一个图出现在第二个应该出现的位置,而在打印所有消息之后,第二个出现。寻找解决方案我发现了这个(使用循环将输出打印到 Knitr 中)
for(i in 1:2) {
print(paste0("before ", i))
plot(i, i)
plot.new()
# This function (frame is an alias for plot.new) causes the completion of
# plotting in the current plot (if there is one) and an advance to a new
# graphics frame.
print(paste0("after ", i))
}
哪个可以解决它,但不幸的是,为每个有效地块创建了空地块。有谁知道在不创建新图形框架的情况下完成绘图的方法?