Description Usage Arguments Value Author(s) See Also Examples
View source: R/animatoR-functions-knitr.R
Add transparency parameter (alpha) to colors
1 | makeTransparent(x, alpha = 0.5)
|
x |
vector specifying colors or factor.
Colors can be specified as numbers or
character strings, see |
alpha |
numeric, transparency value |
A character vector with elements of 7 or 9 characters, "#" followed by the red, blue, green and optionally alpha values in hexadecimal (after rescaling to 0 ... 255). The optional alpha values range from 0 (fully transparent) to 255 (opaque).
Andrej Blejec andrej.blejec@nib.si
rgb
for setting colors and
colors
for color names.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # Transparent red
makeTransparent("red",0.5)
# Same thing
makeTransparent(2,0.5)
# Vector of names
makeTransparent(c("red","orange"),0.75)
# Vector of color numbers
makeTransparent(1:5)
# Factor levels can be used as color indicator
makeTransparent(factor(c("S","M","H","S")))
# Different transparency
makeTransparent(1:5,alpha=1:5)
#
# Define transparent version of base colors
#
trcols<-makeTransparent(c(1:8,0.1),alpha=0.75)
trcols <- data.frame(t(trcols),stringsAsFactors=FALSE)
names(trcols) <-
paste("tr",c("black","red","green","blue",
"cyan","magenta","yellow","grey","white"),sep="")
str(trcols)
attach(trcols)
trred
trgreen
detach()
# Plot colors
if(interactive()){
par(xpd=TRUE)
newplot(stamp=FALSE)
points(1:9,1:9,bg=unlist(trcols),col="grey",pch=21,cex=15)
text((1:9)+1.1,(1:9)-0.7,names(trcols),adj=0)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.