2014-11-08 54 views
0
For (i in 1:3){ 

#…Here I determine the following as data.frame: 1) mean_values, 2) Time, 3) medians, 4) stages, 5) quantiles_mean_values, 6) quantiles_medians… 

    pdf(file="test.pdf", height=9) 
    If (i==1){ 
     One<-ggplot(mean_values,aes(x=Time,y=mean_values)) + 
     geom_line(linetype='dashed')+ 
     scale_y_log10()+ 
     geom_line(data = medians, aes(x = Time, y = median), color="blue")+ 
     geom_point(data = stages, aes(x = Time, y =stages))+   
     geom_ribbon(data=quantiles_mean_values,aes(ymin=X25.,ymax=X75.), alpha=0.4,fill="orange")+ 
     geom_ribbon(data=quantiles_medians,aes(ymin=X25., ymax=X75.),alpha=0.2,fill="blue") 
    } 
    if (i==2) { 
     Two<-ggplot(mean_values,aes(x=Time,y=mean_values)) + 
     geom_line(linetype='dashed')+ 
     scale_y_log10()+ 
     geom_line(data = medians, aes(x = Time, y = median), color="blue")+ 
     geom_point(data = stages, aes(x = Time, y =stages))+ 
     geom_ribbon(data=quantiles_mean_values,aes(ymin=X25., ymax=X75.), alpha=0.4,fill="orange")+ 
     geom_ribbon(data=quantiles_medians,aes(ymin=X25., ymax=X75.), alpha=0.2,fill="blue") 
    } 
    if (i==3){ 
     Three<-ggplot(mean_values,aes(x=Time,y=mean_values)) + 
     geom_line(linetype='dashed')+ 
     scale_y_log10()+ 
     geom_line(data = medians, aes(x = Time, y = median),color="blue")+ 
     geom_point(data = stages, aes(x = Time, y =stages))+ 
     geom_ribbon(data=quantiles_mean_values,aes(ymin=X25.,ymax=X75.),alpha=0.4,fill="orange")+ 
     geom_ribbon(data=quantiles_medians,aes(ymin=X25., ymax=X75.),alpha=0.2,fill="blue") 
    } 
} 
grid.arrange(One, Two, Three, ncol=3,nrow=3) 
dev.off() 

當我註釋掉geom_ribbon(..)時,一切正常。包括geom_ribbon(...)讓我只繪製最後一個數字,即三,並給我一個錯誤的另外兩個,即在循環中添加geom_ribbon僅繪製循環的最後一個圖,並給出R中的錯誤

美學必須是一個長度或相同長度的數據問題:X25。 ,X75

如果我只考慮(我在1:2)它將再次只繪製最後一個數字,即兩個,並給我第一個圖相同的錯誤。如果我只是(我在1:1),它會給我的圖一沒有錯誤。總的來說,似乎情節一,二,三在循環內相互作用,儘管它們不應該。任何幫助,將不勝感激。

+1

歡迎堆棧溢出。爲了更好地幫助我們,請花些時間更清晰地設置問題的格式,包括代碼,以便我們重現錯誤。 – Docconcoct 2014-11-08 04:32:33

回答

0

我認爲你正試圖問這樣一個問題:直到你添加

geom_ribbon(...)

for循環的ggplot工作正常

代碼在那裏。發生這種情況的可能性是因爲for循環不知道在哪裏繪製geom_ribbon的數據?

你可以使用這樣的代碼生成一些隨機數據,所以我們可以運行它並找出它?

矩陣(rbinom(10 * 1000,1 .5),NcoI位=(#把你要的號碼在這裏))