I think you can do this in hexadecimal. To see this, compare the HEX output from rgb(1,0,0) and rgb(1,0,0,0.5):
#FF0000 #FF000080 They differ only by the addition of the alpha digits hex 80 which are (almost) half way between 00 and FF. Making a non-transparent scale transparent is thus just a question of appending the appropriate digits: paste(myScale,"80",sep="") which worked well for my code. As you say, the in built scales support alpha by default ending all their codes in FF. James Sturman wrote > > Hello, > > I can't seem to add transparency to any color ramp I create using > colorRampPalette(). Can someone tell me if it is possible to create > transparent colour ramps? > > I am attempting to map shaded relief under elevation data. I know I can > use the terrain.colors() with the alpha option, but I would prefer to > create my own colour ramp using more vibrant colours. > > My most recent attempt at doing this involved generating multiple rgb > colours with transparency (alpha = 0.5) and then combining these colours > using colorRampPalette(). I am able to use the resulting colour ramp, but > it has no transparency. > > # Make terrain colour ramp > rgb7 <- rgb(red=0, green=255, blue=77, alpha = 0.5, maxColorValue = > 255) > rgb8 <- rgb(red=26, green=255, blue=0, alpha = 0.5, maxColorValue = > 255) > rgb9 <- rgb(red=128, green=255, blue=0, alpha = 0.5, maxColorValue = > 255) > rgb10 <- rgb(red=230, green=255, blue=0, alpha = 0.5, maxColorValue > = 255) > rgb11 <- rgb(red=255, green=255, blue=0, alpha = 0.5, maxColorValue > = 255) > rgb12 <- rgb(red=255, green=229, blue=60, alpha = 0.5, maxColorValue > = 255) > rgb13 <- rgb(red=255, green=219, blue=119, alpha = 0.5, > maxColorValue = 255) > rgb14 <- rgb(red=255, green=224, blue=178, alpha = 0.5, > maxColorValue = 255) > rgb15 <- rgb(red=255, green=255, blue=255, alpha = 0.5, > maxColorValue = 255) > terraincolours <- colorRampPalette(c(rgb7, rgb8, rgb9, rgb10, rgb11, > rgb12, rgb13, rgb14, rgb15)) > > > # Plot map > image(terrain, col = shadecolours(512), axes = TRUE) # plots the > shaded relief > #image(dem, col = terrain.colors(512, alpha = 0.5), add = TRUE) # > this option works, but I don't like the colours in the terrain.colors > pallet. > image(dem, col = terraincolours(512), add = TRUE) # draws the > elevation data with no transparancy and it won't accept an alpha value > Thank you, > > James > > Please consider the environment before printing this email. > > NIWA is the trading name of the National Institute of Water & Atmospheric > Research Ltd. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- View this message in context: http://r.789695.n4.nabble.com/Transparent-color-ramp-problem-tp3729094p4324549.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.