[英]plot() in R - how to shade an area between two vertical lines?
如何遮蔽 plot 中標有兩條紅色豎線的區域? (陰影區域不得受曲線限制)
plot(1980:2019,y,type="l") abline(v=1990,col="red") abline(v=2001,col="red")
提前致謝。
如圖所示使用rect 。 較低的 alpha 值提供更高的透明度。
rect
y <- 1980:2019 plot(y, y) rect(xleft = 1999, xright = 2001, ybottom = par("usr")[3], ytop = par("usr")[4], border = NA, col = adjustcolor("blue", alpha = 0.3))
我會使用 ggplot 這樣做:
library(ggplot2) df = cbind(1980:2019,runif(40,0,1)) df=as.data.frame(df) ggplot() + geom_rect(aes(xmin=1990, xmax=2001,ymin=-Inf,ymax=Inf), fill='red', alpha= 0.3)+ geom_line(data=df,aes(x=V1,y = V2), color = "darkred")+ theme_classic()
[英]R - shade area between two crossing lines with different colors
[英]R - Color or shade area between lines
[英]shade area between two 'ablines' in R
[英]How to fill/shade the area of two lines that overlap in ggplot2?
[英]Shade Area between crossing lines differently with ggplot
[英]Shade area between lines with ggplot2
[英]R: How to fill area between these two dashed lines
[英]R : How to plot with vertical lines break by time?
[英]Coloring the area between two specific lines in R
[英]shading area between two lines in r
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.