使用LaTeX在for循环中生成bean图

时间:2014-06-08 02:13:05

标签: r latex sweave

我正在尝试使用forloop自动生成许多beanplots,并将它们输出到LaTeX文档中。从数据框(成功生成beanplots)开始,我使用下面的代码。目的是将连续的beanmap输出到文档中。我可以通过为每个所需的绘图编写一个beanplot命令来做到这一点(它工作正常),但显然如果我能用forloop做这个会更好。但是,当我尝试使用forloop时,它不输出说9个图,而只输出最后一个图。有关为什么会这样的想法?我尝试过使用fig.keep ='所有'和plot.new(),没有帮助。用Sweave编译。谢谢!

<<beanplots,fig.keep='all'>>=
#fig.keep='all' <- this did not help
suppressPackageStartupMessages(require(beanplot))
for (i in length(unique(Data[['Days']]))){
   # plot.new()   ##  this did not help either
  beanplot(Readings~FactorLevels,
         data=subset(x=Data, subset=(Data[['Days']]==i)),
         main=paste("Day",i,sep=" "),
         cex.axis=0.7)
}
@

1 个答案:

答案 0 :(得分:0)

beanplot适用于莱迪思图形库。因此,当非交互式运行时,它不会自动生成绘图。您必须在调用返回的对象上显式调用print()以生成绘图。尝试

<<beanplots,fig.keep='all'>>=
#fig.keep='all' <- this did not help
suppressPackageStartupMessages(require(beanplot))
for (i in unique(Data[['Days']])){
   # plot.new()   ##  this did not help either
  print(beanplot(Readings~FactorLevels,
         data=subset(x=Data, subset=(Data[['Days']]==i)),
         main=paste("Day",i,sep=" "),
         cex.axis=0.7))
}
@