本文介绍了在特定时间范围内突出显示(阴影)绘图背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在通用图上,时间在x轴上,我想强调一个特定年份的时间段.
On a generic plot, with time on the x-axis, I would like to highlight a period of some specific years.
如何最好地做到这一点?我的想法是,例如,在突出显示的年份中出现一条浅黄色的横条,当然是在情节的后面.
How can I bestly do this? My idea is for example a light yellow bar for the highlighted years, behind the plot of course.
我现在拥有的绘图代码:
The plot code I have now:
pdf("temperature_imfs_big_interm5.pdf", width=6, height=8);
par(mfrow=c(temperature$bigEmdIm5$nimf+1,1), mar=c(2,1,2,1))
for(i in 1:temperature$bigEmdIm5$nimf) {
plot(timeline$big, temperature$bigEmdIm5$imf[,i], type="l", xlab="", ylab="", ylim=range(temperature$bigEmdIm5$imf[,i]), axes=FALSE, main=paste(i, "-th IMF", sep=""))#; abline(h=0)
axis.POSIXct(side=1, at=tickpos$big)
}
plot(timeline$big, temperature$bigEmdIm5$residue, xlab="", ylab="", axes=FALSE, main="residue", type="l")
axis.POSIXct(side=1, at=tickpos$big)
dev.off();
其中温度$ bigEmdIm5是有效模式分解的输出.数据以月为单位,因此我想以01/1950直到12/1950为背景.
Where temperature$bigEmdIm5 is the output of emperical mode decompostion. The data is in months, so I would like to higlight 01/1950 until 12/1950 for example.
推荐答案
使用alpha透明度:
Using alpha transparency:
x <- seq(as.POSIXct("1949-01-01", tz="GMT"), length=36, by="months")
y <- rnorm(length(x))
plot(x, y, type="l", xaxt="n")
rect(xleft=as.POSIXct("1950-01-01", tz="GMT"),
xright=as.POSIXct("1950-12-01", tz="GMT"),
ybottom=-4, ytop=4, col="#123456A0") # use alpha value in col
idx <- seq(1, length(x), by=6)
axis(side=1, at=x[idx], labels=format(x[idx], "%Y-%m"))
或在行后绘制突出显示的区域:
or plot highlighted region behind lines:
plot(x, y, type="n", xaxt="n")
rect(xleft=as.POSIXct("1950-01-01", tz="GMT"),
xright=as.POSIXct("1950-12-01", tz="GMT"),
ybottom=-4, ytop=4, col="lightblue")
lines(x, y)
idx <- seq(1, length(x), by=6)
axis(side=1, at=x[idx], labels=format(x[idx], "%Y-%m"))
box()
这篇关于在特定时间范围内突出显示(阴影)绘图背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!