2015-02-10 66 views
-1

這裏的情節,包括傳說中的代碼:要彩色線條加入到複雜的情節傳奇

png(filename=paste0(filename2, SubNameStr, "_", date, "_", BlankUncertainty, "-percent-blank-unc_", "no_add_unc", "_", " (R#_yyyy-mm-dd_hh-mm-ss).png"), 
    type="cairo", 
    units="cm", 
    width=30, 
    height=15, 
    pointsize=12, 
    res=resolution) 

par(mar =c(10, 4, 4, 2)+0.1) 
plotCI(1:abscissa, 
    LoopVariable[ ,"F_corrected_normed"], 
    xlim=c(0, abscissa + 1), 
    ylim=c(LoopVariable[1,"weighted_mean_fraction_modern"] -  (LoopVariable[1,"weighted_mean_fraction_modern"] * y), 
      LoopVariable[1,"weighted_mean_fraction_modern"] + (LoopVariable[1,"weighted_mean_fraction_modern"] * y)), 
    xaxs="i", 
    yaxs="i", 
    uiw=LoopVariable[ ,"F_corrected_normed_error_NOSYSERR"], err="y", 
    main=(LoopVariable[1,"Samples..Sample_ID"]), 
    xlab="", ylab="F_modern", 
    pch=19 
    ) 
if (LoopVariable[1,"Job..R"] == "14047/2") 
abline(h=IAEA_C2consensus, lwd=1, col="blue", lty=11) 

if (LoopVariable[1,"Job..R"] == "18331/3") 
abline(h=TIRI_Iconsensus, lwd=1, col="blue", lty=11) 

if (LoopVariable[1,"Job..R"] == "24889/3") 
abline(h=FIRI_Cconsensus, lwd=1, col="blue", lty=11) 

if (LoopVariable[1,"Job..R"] == "18331/4") 
abline(h=TIRI_Jconsensus, lwd=1, col="blue", lty=11) 

if (LoopVariable[1,"Job..R"] == "24889/4") 
abline(h=FIRI_DFconsensus, lwd=1, col="blue", lty=11) 

if (LoopVariable[1,"Job..R"] == "24889/5") 
abline(h=FIRI_Econsensus, lwd=1, col="blue", lty=11) 

if (LoopVariable[1,"Job..R"] == "24889/9") 
abline(h=FIRI_Iconsensus, lwd=1, col="blue", lty=11) 

abline(h=LoopVariable[1,"weighted_mean_fraction_modern"], lwd=1, col="red") 
mtext(paste0("no additional error added, ", BlankUncertainty, " Blk unc, ", date)) 
if (LoopVariable[1,"Job..R"] == "14047/2") { 
legend("bottom", 
    xpd = TRUE, 
    inset=c(0,-0.6), 

     legend=c(paste0("degrees of freedom = ", LoopVariable[1,"degrees_of_freedom"]), 
       paste0("Chi square     = ", LoopVariable[1,"Chi_square"]), 
       paste0("Chi square reduced = ", LoopVariable[1,"Chi_square_reduced"]), 
       paste0(" F_weighted_mean = ", LoopVariable[1,"weighted_mean_fraction_modern"]), 
       paste0(" F_consensus   = ", IAEA_C2consensus)) 

       ) 

    } 
else {  

legend("bottom", 
    xpd = TRUE, 
    inset=c(0,-0.6), 

    legend=c(paste0("degrees of freedom ", LoopVariable[1,"degrees_of_freedom"]), 
      paste0("Chi square ", LoopVariable[1,"Chi_square"]), 
      paste0("Chi square reduced ", LoopVariable[1,"Chi_square_reduced"]), 
      paste0(lty=1, col="red", " F_weighted_mean = ", LoopVariable[1,"weighted_mean_fraction_modern"]) 
      ) 
    )} 


dev.off() 

我的問題是,我怎樣才能增加一個簡短的紅色和藍色的線,我的最後一個用於圖例的線條,以便F_consensus和F_weighted_mean值可用於圖中正確的顏色abline。 這裏是形式我的示例代碼生成的情節:要指定的參數ltycol這樣 enter image description here

+0

查看文檔後,它看起來很容易,但它似乎沒有任何測試數據。 (你沒有加載pkg:plotrix。) – 2015-02-10 04:34:53

+0

'@ BondeDust'我確實加載了庫的plotrix,我只是在這裏沒有提到它。對困惑感到抱歉! – Johannes 2015-02-10 19:54:50

回答

0

legendText <- c(paste0("degrees of freedom = ", LoopVariable[1,"degrees_of_freedom"]), 
       paste0("Chi square     = ", LoopVariable[1,"Chi_square"]), 
       paste0("Chi square reduced = ", LoopVariable[1,"Chi_square_reduced"]), 
       paste0(" F_weighted_mean = ", LoopVariable[1,"weighted_mean_fraction_modern"]), 
       paste0(" F_consensus   = ", IAEA_C2consensus)) 
legend("bottom", 
     legendText, 
     xpd = TRUE, 
     inset=c(0,-0.6), 
     col = c(NA,NA,NA,'red','blue'), 
     lty = c(NA,NA,NA,1,2)) 

我通常位置上提供文本標籤(第二個或第三個參數取決於) ,因爲令人困惑的是這裏有一個名爲legend的參數與函數legend()

+0

'@ Jthorpe'當我在傳說中的5行代碼下添加最後兩行代碼時,圖例將擴展三條空行,後面跟着一行內容爲「紅色」,下一行爲「藍色」,三個空行行,下一行顯示「1」,最後一行顯示「2」。我完全同意我必須指定'lty'和'col'參數,但是能否給我完整的解決方案? – Johannes 2015-02-10 20:10:22