Skip to content

making scatter plot points fill semi-transparent

4 messages · per freem, Steve Lianoglou, Gabor Grothendieck +1 more

#
hi all,

i have a simple scatter plot, and i'd like to make it so the scatter
plot colors are slightly transparent. i see in a previous post that
someone mentioned the "alpha" parameter, but i am not sure how it can
be used with the 'plot' function [*].

for example, suppose i have:

plot(mydata$column1, mydata$column2, col="red", cex=1)

i now want to make it so the color of these points (in this case red)
is slightly transparent, which will make overlap between them very
obvious. i realize that hexbin and other density plot methods are used
to make this, but i am using it for a different purpose, and so i just
want the points to be transparent without any binning or shading.

a previous poster suggested:

plot( rnorm(1000), rnorm(1000), col="#0000ff22", pch=16,cex=3)

but i don't understand this color notation. is there any way to pass
in the usual col="colorname" argument and then tweak that color's
transparency?

thank you.

https://stat.ethz.ch/pipermail/r-help/2007-October/142934.html
#
Hi,
On Aug 5, 2009, at 11:48 PM, per freem wrote:

            
It's the usual #RRGGBB color notation, w/ the last two digits  
apparently defining the amount of opacity.

#0000FFFF is blue w/ full opacity

To figure out how to define your color with RGB notation, use a mix of  
col2rgb and rgb functions:

R> col2rgb('blue', alpha=T)
       [,1]
red      0
green    0
blue   255
alpha  255

R> rgb(red=0, green=0, blue=255, alpha=255, max=255)
[1] "#0000FFFF"

Play with different values of alpha (0 < alpha <= 255) in the above  
call to get different levels of opacity for your points.

R> rgb(red=0, green=0, blue=255, alpha=10, max=255)
[1] "#0000FF0A"

R> plot( rnorm(1000), rnorm(1000), col="#0000FF0A", pch=16,cex=3)
Maybe, but I'm not familiar with it.

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
#
Lattice graphics can do that:

library(lattice)
xyplot(0:20 ~ 0:20, alpha = 0:20/20, col = "red", pch = 19, cex = 5)

Google for
  HTML colors
to find out more about the hex codes you are referring to.
On Wed, Aug 5, 2009 at 11:48 PM, per freem<perfreem at gmail.com> wrote:
#
You can also use ggplot2:

library(ggplot2)
x <- rnorm(10000);y <- rnorm(x);myplot <- data.frame(x,y)
qplot(x,y,data= myplot,colour=I(alpha("blue",1/25)))


Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA
--- On Wed, 8/5/09, Gabor Grothendieck <ggrothendieck at gmail.com> wrote: