[R] Plot Rect Transparency

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Fri Jun 29 02:57:19 CEST 2018


On 28/06/2018 5:29 PM, Jeff Reichman wrote:
> R-Help
> 
>   
> 
> Is there a way to make a rectangle transparent (alpha=0.1??)
> 
>   
> 
>    plot(c(100, 200), c(300, 450), type= "n", xlab = "", ylab = "")
> 
>     rect(110, 300, 175, 350, density = 5, border = "red")
> 
>   
> 
> Can't figure out how to take the changepoint function results and plot in
> ggplot2 so I can just simply add rectangles to the plot function, but I need
> to make transparent and there doesn't seem to be an alpha option.

Alpha is part of the colour spec.  For example,

rect(110, 300, 175, 350, density = 5, border = rgb("red")


rect(110, 300, 175, 350, density = 5, border = rgb(red=1, green=0, 
blue=0, alpha=0.1))

I'm not sure what is the quickest way to work out the rgb values for a 
named colour (col2rgb can do it, but not in a convenient format) if you 
want to add alpha to it.

Duncan Murdoch




More information about the R-help mailing list