colorblindr icon indicating copy to clipboard operation
colorblindr copied to clipboard

geom_label() sneaks past cvd_grid()

Open k-hench opened this issue 5 years ago • 4 comments

Hello,

I just wanted to give a short heads up about a minor issue I stumbled upon:

when playing around with this great package I just realized some unexpected behaviour with when using geom_label() in combination cvd_grid() - somehow the color of this particular geom stays untouched:

library(tidyverse)
library(colorblindr)
#> Loading required package: colorspace

p <- tibble(label = 'test') %>%
  ggplot()+
  geom_segment(aes(x = -1, xend = 1,y = 0, yend = 0, color = label))+
  geom_label(aes(x=0,y=0,label = label, color = label))+
  theme_void()

cvd_grid(p)

Created on 2019-08-27 by the reprex package (v0.3.0)

cheers, Kosmas

k-hench avatar Aug 27 '19 08:08 k-hench

Thanks for pointing this out. Unfortunately, I have realized that these kinds of issues are unavoidable. There'll always be some grob that colorblindr can't properly handle. (I'm working on some right now.) Moving forward, it's probably best to just generate an image and then convert that. The colorspace package has an app that simulates color vision deficiency on images. This may be useful for you.

clauswilke avatar Aug 27 '19 13:08 clauswilke

Thanks for the quick note. Following your advice, I reached this solution (which should be independent of special grobs):

library(tidyverse)
library(colorblindr)
#> Loading required package: colorspace
library(cowplot)
#> 
#> ********************************************************
#> Note: As of version 1.0.0, cowplot does not change the
#>   default ggplot2 theme anymore. To recover the previous
#>   behavior, execute:
#>   theme_set(theme_cowplot())
#> ********************************************************
library(grImport2)
library(grConvert)

p <- tibble(label = 'test') %>%
  ggplot()+
  geom_segment(aes(x = -1, xend = 1,y = 0, yend = 0, color = label))+
  geom_label(aes(x=0,y=0,label = label, color = label))+
  theme_void()

ggsave(plot = p,filename = '~/Desktop/p.svg',width = 2,height = 1)
grConvert::convertPicture('~/Desktop/p.svg','~/Desktop/p.c.svg')
#> '/home/khench/Schreibtisch/p.svg' (SVG) was converted to '/home/khench/Schreibtisch/p.c.svg' (Cairo SVG)

p_detour <- ggdraw(grImport2::readPicture('~/Desktop/p.c.svg') %>% 
                     grImport2::pictureGrob(.))

cvd_grid(p_detour)

Created on 2019-08-27 by the reprex package (v0.3.0)

k-hench avatar Aug 27 '19 14:08 k-hench

Please don't close the issue. It is real, and I may look into fixing it at some point.

clauswilke avatar Aug 27 '19 14:08 clauswilke

ups, sorry (I'm still github newbie...)

k-hench avatar Aug 27 '19 14:08 k-hench