Plot Rect Transparency

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Plot Rect Transparency

reichmaj
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.

 

Jeff


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Plot Rect Transparency

Duncan Murdoch-2
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

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Plot Rect Transparency

reichmaj
Duncan

Thanks I was able to find it in the help doc.

x <- c(1,2,4,6,8,9,10,12,13,14,18,20)
y <- c(4,5,3,6,7,4,8,9,12,4,7,5)

mydata <- data.frame(x,y)

plot(mydata)
rect(5,0,8,8, col=rgb(0,1,0,alpha=0.2), border=F)

-----Original Message-----
From: Duncan Murdoch <[hidden email]>
Sent: Thursday, June 28, 2018 7:57 PM
To: [hidden email]; [hidden email]
Subject: Re: [R] Plot Rect Transparency

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

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Plot Rect Transparency

Martin Maechler
In reply to this post by Duncan Murdoch-2
>>>>> Duncan Murdoch
>>>>>     on Thu, 28 Jun 2018 20:57:19 -0400 writes:

    > 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.

IIUC, it is adjustcolor() you were thinking of.  It had been
created to do that and more.

I'm using that "all the time" nowadays in my graphics code,
e.g.,

> adjustcolor("red", 2/3)
[1] "#FF0000AA"

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.