Dear list, The dichromat package defines a dichromat function which "Collapses red-green color distinctions to approximate the effect of the two common forms of red-green colour blindness, protanopia and deuteranopia." library(dichromat) library(grid) colorStrip <- function (colors = 1:3, draw = TRUE) { x <- seq(0, 1 - 1/length(colors), length = length(colors)) y <- rep(0.5, length(colors)) my.grob <- grid.rect(x = unit(x, "npc"), y = unit(y, "npc"), width = unit(1/length(colors), "npc"), height = unit(1, "npc"), just = "left", hjust NULL, vjust = NULL, default.units = "npc", name = NULL, gp = gpar(fill = colors, col = colors, draw draw, vp = NULL)) my.grob } colorStrip(1:3) colorStrip(dichromat(1:3)) Now what would be nice is a function that can edit the colours (col and fill parameters) of an existing grob. dichromatit <- function(x){ .NotYetImplemented() } dichromatit(colorStrip()) It could allow high-level testing for visual perception of lattice and ggplot2 plots, p1 = xyplot(1~1) p2 = qplot(1,1, colour= I("red")) dichromatit(p1) p2 + dichromatit() One approach could be to use only integer codes for colours, and modify the current palette() (works also for base graphics). But this is quite a stringent request for lattice and ggplot2 which define many named colours in their various themes and scales. Therefore I'd like to think of an approach based on a recursive modification of a grob's gpar components. Does this seem doable with some regular expression magic [*]? All the best, baptiste [*]: http://xkcd.com/208/
Replying to myself here, Hadley pointed out this website on the ggplot2 mailing list, http://colororacle.cartography.ch/ And this seems like a more straight-forward solution to my query (albeit not using R). It sort of makes sense to momentarily alter the computer display rather than parse the code for colour and fill regular expressions... baptiste 2009/9/28 baptiste auguie <baptiste.auguie at googlemail.com>:> Dear list, > > The dichromat package defines a dichromat function which "Collapses > red-green color distinctions to approximate the effect of the two > common forms of red-green colour blindness, protanopia and > deuteranopia." > > library(dichromat) > library(grid) > > colorStrip <- > ?function (colors = 1:3, draw = TRUE) > { > ?x <- seq(0, 1 - 1/length(colors), length = length(colors)) > ?y <- rep(0.5, length(colors)) > ?my.grob <- grid.rect(x = unit(x, "npc"), y = unit(y, "npc"), > ? ? ? ? ? ? ? ? ? ? ? width = unit(1/length(colors), "npc"), > ? ? ? ? ? ? ? ? ? ? ? height = unit(1, "npc"), just = "left", hjust > NULL, vjust = NULL, > ? ? ? ? ? ? ? ? ? ? ? default.units = "npc", name = NULL, > ? ? ? ? ? ? ? ? ? ? ? gp = gpar(fill = colors, col = colors, draw > draw, vp = NULL)) > ?my.grob > } > colorStrip(1:3) > colorStrip(dichromat(1:3)) > > Now what would be nice is a function that can edit the colours ?(col > and fill parameters) of an existing grob. > > dichromatit <- function(x){ > ?.NotYetImplemented() > } > > dichromatit(colorStrip()) > > It could allow high-level testing for visual perception of lattice and > ggplot2 plots, > > p1 = xyplot(1~1) > p2 = qplot(1,1, colour= I("red")) > > dichromatit(p1) > p2 + dichromatit() > > > One approach could be to use only integer codes for colours, and > modify the current palette() (works also for base graphics). But this > is quite a stringent request for lattice and ggplot2 which define many > named colours in their various themes and scales. Therefore I'd like > to think of an approach based on a recursive modification of a grob's > gpar components. Does this seem doable with some regular expression > magic [*]? > > All the best, > > baptiste > > > > > [*]: http://xkcd.com/208/ >
baptiste auguie <baptiste.auguie <at> googlemail.com> writes:> Replying to myself here, > Hadley pointed out this website on the ggplot2 mailing list, > > http://colororacle.cartography.ch/ > > And this seems like a more straight-forward solution to my query > (albeit not using R). It sort of makes sense to momentarily alter the > computer display rather than parse the code for colour and fill > regular expressions... > 2009/9/28 baptiste auguie <baptiste.auguie <at> googlemail.com>: > > Dear list,> > The dichromat package defines a dichromat function which "Collapses > > red-green color distinctions to approximate the effect of the two > > common forms of red-green colour blindness, protanopia and > > deuteranopia."> > All the best, > > > > baptisteJust to point out a fact or two with respect to the information on the indicated web page and a statement above. While roughly 8% of males are classified as color-deficient by standard tests, as indicated at the site to which the link points, only about 2% are actually dichromats, i.e., protanopes and deuteranopes, referred to above as "common forms", and to which the dichromat package is directly relevant. Dichromatic vision is reduced to 2 dimensions from the normal 3. Most of the other 6% (i.e., the most common forms) are what are termed anomalous trichromats and to whom the renditions of the dichromat package are not actually appropriate, as the color spaces of such observers are not a subspace of that of a normal observer. Such individuals really see the world a bit differently, as they may very well call something as red that a normal observer would call green or vice versa depending what kind of anomalous trichromat one is. So, strictly speaking, the dichromat package is of great value in avoiding color choices that about 1% of the population would have trouble discriminating. Ken -- Ken 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