Last data update: 2014.03.03

R: colors to transparent colors
col2transR Documentation

colors to transparent colors

Description

transform color names to transparent versions of rgb color codes

Usage

col2trans(col.names,alpha=0.5)

Arguments

col.names

Vector. Vector of color names from colors.

alpha

Number. Number between 0 and 1 giving alpha channel (opacity) value

Details

Translates a vector of color names to a vector of transparent rgb color codes. Color names must be from names given by colors.

Value

Outputs a vector of transparent color codes.

Author(s)

Elizabeth Freeman

Examples


col.names=c("blue","violetred4","thistle3","yellowgreen")
col2trans(col.names,alpha=.2)


###to see effect of alpha###

alpha<-(0:10)/10
colmat<-matrix(	1:(length(alpha)*length(col.names)),
			nrow=length(alpha),
			ncol=length(col.names),
			byrow=TRUE)

color.codes<-vector("character",0)

for(i in 1:length(alpha)){
	color.codes<-c(color.codes,col2trans(col.names,alpha=alpha[i]))
}

#make plot#
plot(	c(0,1),c(0,1),
	type="n",xlab="alpha",ylab="color name",yaxt="n",xaxs="i",yaxs="i")
abline(h=(0:100)/100)
image(	z=colmat,
		x=(0:length(alpha))/length(alpha),
		y=(0:length(col.names))/length(col.names),
		col=color.codes,
		add=TRUE
		)
op<-par(xpd=TRUE)
text(	col.names,
	x=-.08,
	y=(1:length(col.names)-.5)/length(col.names),
	srt=90)
par(op)


Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ModelMap)
Loading required package: randomForest
randomForest 4.6-12
Type rfNews() to see new features/changes/bug fixes.
Loading required package: raster
Loading required package: sp
Loading required package: rgdal
rgdal: version: 1.1-10, (SVN revision 622)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 1.11.3, released 2015/09/16
 Path to GDAL shared files: /usr/share/gdal/1.11
 Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
 Path to PROJ.4 shared files: (autodetected)
 Linking to sp version: 1.2-3 
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ModelMap/col2trans.Rd_%03d_medium.png", width=480, height=480)
> ### Name: col2trans
> ### Title: colors to transparent colors
> ### Aliases: col2trans
> ### Keywords: models
> 
> ### ** Examples
> 
> 
> col.names=c("blue","violetred4","thistle3","yellowgreen")
> col2trans(col.names,alpha=.2)
[1] "#0000FF33" "#8B225233" "#CDB5CD33" "#9ACD3233"
> 
> 
> ###to see effect of alpha###
> 
> alpha<-(0:10)/10
> colmat<-matrix(	1:(length(alpha)*length(col.names)),
+ 			nrow=length(alpha),
+ 			ncol=length(col.names),
+ 			byrow=TRUE)
> 
> color.codes<-vector("character",0)
> 
> for(i in 1:length(alpha)){
+ 	color.codes<-c(color.codes,col2trans(col.names,alpha=alpha[i]))
+ }
> 
> #make plot#
> plot(	c(0,1),c(0,1),
+ 	type="n",xlab="alpha",ylab="color name",yaxt="n",xaxs="i",yaxs="i")
> abline(h=(0:100)/100)
> image(	z=colmat,
+ 		x=(0:length(alpha))/length(alpha),
+ 		y=(0:length(col.names))/length(col.names),
+ 		col=color.codes,
+ 		add=TRUE
+ 		)
> op<-par(xpd=TRUE)
> text(	col.names,
+ 	x=-.08,
+ 	y=(1:length(col.names)-.5)/length(col.names),
+ 	srt=90)
> par(op)
> 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>