想在复杂的情节图例中添加彩色线条
want to add colored lines into complex plot legend
这是包含图例的情节代码:
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
。
这是从我的示例代码中生成的图:
您想像这样指定参数 lty
和 col
:
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()
.
这是包含图例的情节代码:
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
。
这是从我的示例代码中生成的图:
您想像这样指定参数 lty
和 col
:
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()
.