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

docs: make scales diverge using a midpoint and rescale #768

Closed
davidhodge931 opened this issue Apr 3, 2024 · 0 comments
Closed

docs: make scales diverge using a midpoint and rescale #768

davidhodge931 opened this issue Apr 3, 2024 · 0 comments
Labels

Comments

@davidhodge931
Copy link
Owner

10. Centre a diverging colour scale

Sometimes you need to centre a diverging colour scale.

mpg |>
  mutate(centred = cty - mean(cty)) |>
  select(displ, hwy, centred) %>%
  gg_point(
    x = displ,
    y = hwy,
    col = centred,
    col_pal = c(teal, "#E8EFF2", orange),
    col_limits = max(abs(.$centred)) * c(-1, 1),
  )
mpg |>
  mutate(centred = cty - mean(cty)) |>
  select(displ, hwy, centred) %>%
  gg_point(
    x = displ,
    y = hwy,
    col = centred,
    col_pal = c(teal, "#E8EFF2", orange),
    col_rescale = scales::rescale(sort(c(range(.$centred), 0)))
  )
@davidhodge931 davidhodge931 changed the title docs: diverging scales docs: make scales diverge using a midpoint and rescale Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant