string - Applying transparency to a vector of colors in plot function -
i trying use alpha
conversion col
argument in plot
function. how do without having write col=alpha(each_color,.5)
each_color
.
is there way vectorize that?
here reproducible example:
set.seed(10) mydata <- rnorm(100) mycol <-c("#fdf6e3", "#b3e2cd", "#fdcdac", "#cbd5e8", "#f4cae4", "#e6f5c9", "#fff2ae", "#f1e2cc", "#cccccc") par(bg='gray30') plot(mydata,col=mycol,pch=19,cex=3) mycol_alpha <- paste0('alpha(\'',mycol,'\',.5)') par(bg='white')
is there way apply mycol_alpha
plot
function directly or other way?
update:
this 1 has solution. mistake, thought alpha function
in base r
. need library(scales)
solution:
set.seed(10) mydata <- rnorm(100) mycol <-c("#fdf6e3", "#b3e2cd", "#fdcdac", "#cbd5e8", "#f4cae4", "#e6f5c9", "#fff2ae", "#f1e2cc", "#cccccc") par(bg='gray30') plot(mydata,col=scales::alpha(mycol,.5),pch=19,cex=3)
vectorization not problem noted @robert.
add
transparency<-round(255*0.5)
# 50% alpha
and try
mycol_alpha <- paste0(mycol,as.hexmode(transparency))
that should add transparency in plot( ... , col=mycol_alpha , ...)
no need scales::alpha.
Comments
Post a Comment