Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a transparent rectangle to a R boxplot (plot)?

I have a simple boxplot for my data using R ..

boxplot (Error~Code, DataFrame1, xlim = c(0, 27),
     xlab="set Code",ylab="Error", boxwex=0.75, cex.axis=0.3)

and I would like to draw a transparent rectangle all over the plot between 2 defined y-values: (-50 ) and (100)!

I tried using the function rect as follows after the previous script:

  rect(0,-50,27,100, col= 'tomato2', density=10)

but this does not give me a uniform colored rectangle with transparency!!

Could anybody please help me in that? I almost spend over 2 hours until now on this with no success.

Many thanks in advance!

like image 961
Leo... Avatar asked Aug 05 '13 10:08

Leo...


1 Answers

density will result in cross hatching, which is not what you want. What you want is alpha blending.

Try

# 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))
like image 166
Mark Lakata Avatar answered Oct 15 '22 17:10

Mark Lakata