可以添加一个选项 polygon 对于 hmin2 在循环之外。要添加图例,您应该增加绘图区域( xlim 和 ylim ),所以传说将是可见的。
polygon
hmin2
xlim
ylim
plot(NULL, xlim=c(FullRange[1]-1, FullRange[2] +1), ylim=c(-1,4), yaxt="n", xlab="Value", ylab="") abline(v=19.293) axis(2, at=(0:2)+0.4, labels=c("hmin1", "hmin2","hmin3"), lty=0, las=2) for(i in c(1,3)) { polygon(c(BoxRanges[[i]][1], BoxRanges[[i]][1], 19.293, 19.293), c(i-1,i-0.2,i-0.2,i-1), col="red") polygon(c(19.293, 19.293, BoxRanges[[i]][2], BoxRanges[[i]][2]), c(i-1,i-0.2,i-0.2,i-1), col="blue") } i = 2 polygon(c(BoxRanges[[i]][1], BoxRanges[[i]][1], 19.293, 19.293), c(i-1,i-0.2,i-0.2,i-1), col="blue") polygon(c(19.293, 19.293, BoxRanges[[i]][2], BoxRanges[[i]][2]), c(i-1,i-0.2,i-0.2,i-1), col="red") legend(x = 20, y = 4.5, legend = "negative changes", border = NULL, fill = "red", bty = "n", bg = "n") legend(x = 20, y = 4, legend = "positive changes", border = NULL, fill = "blue", bty = "n", bg = "n")
如果要为绘图添加标题,则必须使用 main 内 plot 。要在线上添加标签,您可以使用 text :
main
plot
text
plot(NULL, xlim=c(FullRange[1]-1, FullRange[2] +1), ylim=c(-1,4), yaxt="n", xlab="Value", ylab="", main = "Range of H min values with parameter changes") abline(v=19.293) axis(2, at=(0:2)+0.4, labels=c("hmin1", "hmin2","hmin3"), lty=0, las=2) for(i in c(1,3)) { polygon(c(BoxRanges[[i]][1], BoxRanges[[i]][1], 19.293, 19.293), c(i-1,i-0.2,i-0.2,i-1), col="red") polygon(c(19.293, 19.293, BoxRanges[[i]][2], BoxRanges[[i]][2]), c(i-1,i-0.2,i-0.2,i-1), col="blue") } i = 2 polygon(c(BoxRanges[[i]][1], BoxRanges[[i]][1], 19.293, 19.293), c(i-1,i-0.2,i-0.2,i-1), col="blue") polygon(c(19.293, 19.293, BoxRanges[[i]][2], BoxRanges[[i]][2]), c(i-1,i-0.2,i-0.2,i-1), col="red") legend(x = 20, y = 4.5, legend = "negative changes", border = NULL, fill = "red", bty = "n", bg = "n") legend(x = 20, y = 4, legend = "positive changes", border = NULL, fill = "blue", bty = "n", bg = "n") text(x = 17.5, y = -0.9, labels ="19.293", col = "black", cex = 0.9)