Hi, I have tried to find a way to find opposite or complementary colors in R. I would like to form a color circle with R like this one: http://nobetty.net/dandls/colorwheel/complementary_colors.jpg If you just make a basic color wheel in R, the colors do not form complementary color circle: palette(rainbow(24)) Colors=palette() pie(rep(1, 24), col = Colors) There is a package ?colortools? where you can find function opposite(), but it doesn?t work as is said. I tried library(colortools) opposite("violet") and got green instead of yellow and opposite("blue") and got yellow instead of orange. Do you know any solutions? Atte Tenkanen
> On 25 Jul 2015, at 21:49 , Atte Tenkanen <attenka at utu.fi> wrote: > > Hi, > > I have tried to find a way to find opposite or complementary colors in R. > > I would like to form a color circle with R like this one: http://nobetty.net/dandls/colorwheel/complementary_colors.jpg > > If you just make a basic color wheel in R, the colors do not form complementary color circle: > > palette(rainbow(24)) > Colors=palette() > pie(rep(1, 24), col = Colors) > > There is a package ?colortools? where you can find function opposite(), but it doesn?t work as is said. I tried > > library(colortools) > opposite("violet") and got green instead of yellow and > > opposite("blue") and got yellow instead of orange. > > Do you know any solutions?Not directly, but a few hints: First read up on "complementary colors" in Wikipedia. In particular, note that the traditional color circle does not satisfy the modern definition of opposite-ness. E.g. red paint mixed with green paint is brown, not black or grey. The construction of the color circle is simple in principle: red, blue, yellow go at 0, 120, 240 degrees, the other colors on the circle are formed by mixing two primaries in varying proportions: green (at 180 deg) is an equal mixture of blue and yellow, violet (at 60 deg) of blue and red, orange (at 300 deg) of red and yellow. Blue-green (at 150 deg) would be half blue, half green, alias three quarter blue, one quarter yellow. Etc. The tricky bit is that the above mixtures are subtractive mixtures (mixing paint rather than light beams) and I don't know how to make a subtractive color mixture in the additive RGB space that we usually work in. Maybe there are tools in the colortools package? -pd> > Atte Tenkanen > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
peter dalgaard <pdalgd <at> gmail.com> writes:> > > > On 25 Jul 2015, at 21:49 , Atte Tenkanen<attenka <at> utu.fi> wrote:> > > > Hi, > > > > I have tried to find a way to find oppositeor complementary colors in R.> > > > I would like to form a color circle with Rlike this one: http://nobetty.net/dandls/ colorwheel/complementary_colors.jpg> > > > If you just make a basic color wheel in R,the colors do not form complementary color circle:> > > > palette(rainbow(24)) > > Colors=palette() > > pie(rep(1, 24), col = Colors) > > > > There is a package ?colortools? whereyou can find function opposite(), but it doesn?t work as is> said. I tried > > > > library(colortools) > > opposite("violet") and got green instead of yellow and > > > > opposite("blue") and got yellow instead of orange. > > > > Do you know any solutions? > > Not directly, but a few hints: > > First read up on "complementary colors" inWikipedia. In particular, note that the traditional color> circle does not satisfy the modern definitionof opposite-ness. E.g. red paint mixed with green paint is> brown, not black or grey. > > The construction of the color circle is simplein principle: red, blue, yellow go at 0, 120, 240 degrees, the> other colors on the circle are formed by mixingtwo primaries in varying proportions: green (at 180 deg) is> an equal mixture of blue and yellow, violet(at 60 deg) of blue and red, orange (at 300 deg) of red and yellow.> Blue-green (at 150 deg) would be half blue,half green, alias three quarter blue, one quarter yellow. Etc.> > The tricky bit is that the above mixtures aresubtractive mixtures (mixing paint rather than light beams)> and I don't know how to make a subtractivecolor mixture in the additive RGB space that we usually work in.> Maybe there are tools in the colortools package? > > -pd > > > > > Atte TenkanenTo start with, you should be specifying your "colors" or lights actually in an additive color space like CIE 1931 xy, https://en.wikipedia.org/wiki/CIE_1931_color_space which you can do in the colorspace package. But this is based on an average observer and the results are unlikely to match a given individual's vision. On top of that, decisions made when this norm was specified are such that it deviates from human vision for short wavelengths so that you would be better off using a corrected version like that proposed by Judd in the 1950's or for the most recent suggestion see ww.cvrl.org under New CIE XYZ functions transformed from the CIE (2006) LMS functions best, Ken -- Kenneth Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen L?pine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html
Dear Atte Tenkanen, Re:> Hi, > > I have tried to find a way to find opposite or complementary colors in R. > > I would like to form a color circle with R like this one: http://nobetty.net/dandls/colorwheel/complementary_colors.jpg > > If you just make a basic color wheel in R, the colors do not form complementary color circle: > > palette(rainbow(24)) > Colors=palette() > pie(rep(1, 24), col = Colors) > > There is a package ?colortools? where you can find function opposite(), but it doesn?t work as is said. I tried > > library(colortools) > opposite("violet") and got green instead of yellow and > > opposite("blue") and got yellow instead of orange. > > Do you know any solutions? > > Atte TenkanenActually, yellow and blue are complementary colours, but red and green aren't. The human visual system has three types of cones: red-sensitive, green-sensitive and blue-sensitive. (the labels are approximate, e.g. red-sensitive cones have their optimum sensitivity at a wavelength we might call orange, but for understanding colours, R-G-B is the useful standard designation). A certain combination of these three together, such as in sunlight, is seen as white. In the digital domain, the three "colour channels" of an image are usually scaled to 8-bit numbers, i.e. from zero up to and including 255. So, all three channels 255 makes white. Leaving one of the three colors out yields yellow (no blue), magenta (no green) and cyan (no red). The pairs yellow-blue, magenta-green and cyan-red are truly complementary colours. Colours are the result of the wavelength of the light, so one would expect colours to lie on a linear scale, from about 700 nm (red), through 550 (green) to about 440 nm (blue). There is a complication, however: the photosensitive pigment of our red cones has a second action peak past that of the blue cones, so past pure blue we see a sort of reddish blue, in other words violet or purple. Therefore, the colours can be plotted in a circle, where violet and purple fill the gap between blue and red. Using a combination of the three ground colors R, G and B, any desired colour shade can be composed. Orange, for example, consists of (approximately) all red and half green. - - - - - - - - - R has ample possibilities to compose colours or colour palettes, with which one can create (almost continuous) gradients or stepwise colour patches. Examples are col2rgb():>col2rgb("orange")[,1] red 255 green 165 blue 0>col2rgb("violet")[,1] red 238 green 130 blue 238 Cindy Brewer wrote a fine set of colour functions, adapted to R by Erich Neuwirth. See package "RColorBrewer". And much can be done with the standard R distribution: The following code plots a some colours in a circle, with the complementary colours at opposite sides (so crudely what you're after): # define colour triplets reds = c( 255, 255, 255, 0, 0, 0, 0, 128) greens = c( 0, 127, 255, 255, 255, 127, 0, 0) blues= c( 0, 0, 0, 0, 255, 255, 255, 255) n = length(reds) # compute circle to plot in stp = 2*pi/n th = seq(0,2*pi-stp, length.out=n) x = cos(th); y=sin(th) # plot (on a Mac, for other OSses call the appropriate grahics window quartz(w=5, h=5) par(xpd=NA) plot(x,y,pch=15, cex=8, col=rgb(reds, greens, blues, maxColorValue = 255), asp=1, axes=FALSE, xlab='', ylab='') points(x,y,pch=0, cex=8, col="black") # arrows connect the complementary colours arrows(0,0, 0.7*x, 0.7*y, length = 0.25, col = "grey") Hope this helps; Best wishes, Frank ------ Franklin Bretschneider Dept of Biology Utrecht University bretschr at xs4all.nl
I wonder if the hcl colour space is useful? Varying hue while keeping chroma and luminosity constant should give varying colours of perceptually the same "colourness" and brightness. ?hcl pie(rep(1,12),col=hcl((1:12)*30,c=70),border=NA) -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Atte Tenkanen Sent: Sunday, 26 July 2015 7:50a To: r-help at r-project.org Subject: [R] Opposite color in R Hi, I have tried to find a way to find opposite or complementary colors in R. I would like to form a color circle with R like this one: http://nobetty.net/dandls/colorwheel/complementary_colors.jpg If you just make a basic color wheel in R, the colors do not form complementary color circle: palette(rainbow(24)) Colors=palette() pie(rep(1, 24), col = Colors) There is a package ?colortools? where you can find function opposite(), but it doesn?t work as is said. I tried library(colortools) opposite("violet") and got green instead of yellow and opposite("blue") and got yellow instead of orange. Do you know any solutions? Atte Tenkanen ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.