15

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!

Leo...
  • 321
  • 2
  • 4
  • 14
  • 10
    Define the colour using hex. eg rect(0,-50,27,100 ,col= '#FF003322'). The first 6 numbers give the red colour and the last two the level of transparency (i think) – user20650 Aug 05 '13 at 12:12

1 Answers1

13

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))
Antoni
  • 342
  • 2
  • 7
Mark Lakata
  • 19,989
  • 5
  • 106
  • 123