透明性でコーディングすることができますカラー引数も同様です。 0(完全に透明)と255(完全に可視)の間の透明度をコードする2つの16進数だけです。私はこれまで色ベクトルに透明度を追加するためにこの関数を書いていましたが、おそらくここでは役に立ちますか?
addTrans <- function(color,trans)
{
# This function adds transparancy to a color.
# Define transparancy with an integer between 0 and 255
# 0 being fully transparant and 255 being fully visable
# Works with either color and trans a vector of equal length,
# or one of the two of length 1.
if (length(color)!=length(trans)&!any(c(length(color),length(trans))==1)) stop("Vector lengths not correct")
if (length(color)==1 & length(trans)>1) color <- rep(color,length(trans))
if (length(trans)==1 & length(color)>1) trans <- rep(trans,length(color))
num2hex <- function(x)
{
hex <- unlist(strsplit("ABCDEF",split=""))
return(paste(hex[(x-x%%16)/16+1],hex[x%%16+1],sep=""))
}
rgb <- rbind(col2rgb(color),trans)
res <- paste("#",apply(apply(rgb,2,num2hex),2,paste,collapse=""),sep="")
return(res)
}
いくつかの例:
cols <- sample(c("red","green","pink"),100,TRUE)
# Fully visable:
plot(rnorm(100),rnorm(100),col=cols,pch=16,cex=4)
# Somewhat transparant:
plot(rnorm(100),rnorm(100),col=addTrans(cols,200),pch=16,cex=4)
# Very transparant:
plot(rnorm(100),rnorm(100),col=addTrans(cols,100),pch=16,cex=4)
私が点のみの単一のグループにRGBの設定を追加することができそうです。これを複数のグループにどのように適用できますか? – Steve
例:2つの異なる色:点((1:10)+0.05、col = rgb(c(0,0)、c(1,0)、c(0,1)、rep(0.5,2)) 、pch = 16) '(同じ6色のアプローチを使うことができます) – sgibb