[R] dichromat, regexp, and grid objects

baptiste auguie baptiste.auguie at googlemail.com
Wed Sep 30 10:09:56 CEST 2009


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/
>




More information about the R-help mailing list