如何将透明矩形添加到R方框图(plot)?

如何将透明矩形添加到R方框图(plot)?,r,plot,transparent,boxplot,rectangles,R,Plot,Transparent,Boxplot,Rectangles,我有一个简单的箱线图,用R.表示我的数据 boxplot (Error~Code, DataFrame1, xlim = c(0, 27), xlab="set Code",ylab="Error", boxwex=0.75, cex.axis=0.3) 我想在图上画一个透明的矩形,在两个定义的y值之间:(-50)和(100) 在上一个脚本之后,我尝试使用函数rect,如下所示: rect(0,-50,27,100, col= 'tomato2', density=10) 但这

我有一个简单的箱线图,用R.表示我的数据

boxplot (Error~Code, DataFrame1, xlim = c(0, 27),
     xlab="set Code",ylab="Error", boxwex=0.75, cex.axis=0.3)
我想在图上画一个透明的矩形,在两个定义的y值之间:(-50)和(100)

在上一个脚本之后,我尝试使用函数rect,如下所示:

  rect(0,-50,27,100, col= 'tomato2', density=10)
但这并没有给我一个均匀的透明矩形

谁能帮我一下吗?到目前为止,我几乎花了两个多小时在这上面,但都没有成功


非常感谢

密度
将导致交叉阴影,这不是您想要的。你想要的是阿尔法混合

试一试


使用十六进制定义颜色。例如rect(0,-50,27100,col='#FF003322')。前6个数字表示红色,后两个数字表示透明度级别(我认为)有效!你太棒了!!!谢谢!我真的很感激:)
# arguments to rgb(r,g,b and alpha) should be between 0 and 1.0
# this will make transparent blue
rect(x0,y0,x1,y1, col= rgb(0,0,1.0,alpha=0.5))