我已經成功繪製了使用Java,JavaGD和R的單個圖。我遵循this教程。使用Java,R和JavaGD繪製多個圖的問題?
現在,我有一個R-script,它讀取一個CSV文件,進行一些計算。最後,它繪製了8個不同的圖表。當我使用Java/JavaGD運行此腳本時,只有第1和第8個圖是可見的。第二到第七是在「無效」窗口,這是空白的。我使用與上述鏈接/教程完全相同的代碼。所以我猜想有些東西正在被覆蓋。
如何在合適的窗口上繪製它們?此外,如果重新調整大小,第一個窗口將變爲空白。如何解決這個問題?
如果需要,請不要猶豫,要求澄清。我不確定我是如何解釋這個問題的。
任何幫助/閱讀材料非常感謝。
更新1:
目前,我正在使用此代碼:腳本
public static void main(String[] args) {
// TODO Auto-generated method stub
Rengine re;
String[] dummyArgs = new String[1];
dummyArgs[0] = "--vanilla";
re = new Rengine(dummyArgs, false, null);
re.eval("library(JavaGD)");
// This is the critical line: Here, we tell R that the JavaGD() device that
// it is supposed to draw to is implemented in the class MyJavaGD. If it were
// in a package (say, my.package), this should be set to
// my/package/MyJavaGD1.
re.eval("Sys.putenv('JAVAGD_CLASS_NAME'='test/MyJavaGD1')");
re.eval("JavaGD()");
// re.eval("plot(c(1,5,3,8,5), type='l', col=2)");
// re.eval("source(\"C:\\Documents and Settings\\username\\My Documents\\Test Data\\BoxPlot.r\");");
re.eval("source(\"C:\\\\Documents and Settings\\\\username\\\\My Documents\\\\sampleRScript.R\")");
re.end();
System.out.println("Done!");
}
部分:
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="1"))
boxplot(Lift ~ def, data=PlotData, main="Number 1")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
win.graph()
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="2"))
boxplot(Lift ~ def, data=PlotData, main="Number 2")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
win.graph()
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="3"))
boxplot(Lift ~ def, data=PlotData, main="Number 3")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
.
.
.
我們看到鏈接一些代碼繪製一個情節,但你不顯示您用來繪製8個圖的代碼。嘗試將其歸結爲一小段R代碼,它可以再現您的問題。這會幫助我們更容易。 – 2012-01-03 22:09:14
@PaulHiemstra:我使用與鏈接中相同的代碼。我已經更新了這個問題。請看一看。 – Bhushan 2012-01-04 15:01:14