Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_label() sneaks past cvd_grid() #15

Open
k-hench opened this issue Aug 27, 2019 · 4 comments
Open

geom_label() sneaks past cvd_grid() #15

k-hench opened this issue Aug 27, 2019 · 4 comments

Comments

@k-hench
Copy link

k-hench commented Aug 27, 2019

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

@clauswilke
Copy link
Owner

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.

@k-hench
Copy link
Author

k-hench commented Aug 27, 2019

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 k-hench closed this as completed Aug 27, 2019
@clauswilke
Copy link
Owner

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

@clauswilke clauswilke reopened this Aug 27, 2019
@k-hench
Copy link
Author

k-hench commented Aug 27, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants