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

add code based on grid::viewport() to add rotated legend #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

e-kotov
Copy link

@e-kotov e-kotov commented Apr 20, 2023

Hi, I kindly suggest to add a short code snippet to README and one of the vignettes. This code allows to add 45-degree rotated biscale legends for better readability of labels. The easiest way to achieve this, since cowplot functions do not support rotation of inlets, is to use grid::viewport().

Preparation steps from your own readme:

library(biscale)
library(ggplot2)
library(cowplot)
library(sf)

data <- bi_class(stl_race_income, x = pctWhite, y = medInc, style = "quantile", dim = 3)

map <- ggplot() +
  geom_sf(data = data, mapping = aes(fill = bi_class), color = "white", size = 0.1, show.legend = FALSE) +
  bi_scale_fill(pal = "GrPink", dim = 3) +
  labs(
    title = "Race and Income in St. Louis, MO",
    subtitle = "Dark Blue (DkBlue) Palette"
  ) +
  bi_theme()

My addition:

library(grid)
legend <- bi_legend(pal = "GrPink",
                    dim = 3,
                    xlab = "Higher % White ",
                    ylab = "Higher Income ",
                    size = 20)
print(map)
print(legend, vp = grid::viewport(x = 0.4, y = .75, width = 0.2, height = 0.2, angle = -45))

biscale 007

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

Successfully merging this pull request may close these issues.

1 participant