Skip to content

turtletopia/gglgbtq

Repository files navigation

gglgbtq

Lifecycle: experimental CRAN status R-CMD-check Codecov test coverage

gglgbtq provides multiple palettes based on flags in LGBTQ community. These palettes are accompanied by ggplot2 themes that maximize readability of each palette (especially of the white strip that is present in most flags).

Installation

# Install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("turtletopia/gglgbtq")

User guide

To list all available palettes, call:

show_pride()
## # A tibble: 41 × 2
##    palettes     lengths
##    <chr>          <int>
##  1 rainbow            6
##  2 lesbian            5
##  3 gay                5
##  4 bisexual           3
##  5 transgender        3
##  6 asexual            4
##  7 intersex           2
##  8 nonbinary          4
##  9 philadelphia       8
## 10 progress          11
## # ℹ 31 more rows

The most common use case is to use palettes with ggplot2:

library(ggplot2)

data <- data.frame(
  group = rep(c("yes", "no", "maybe"), each = 3) |>
    as.factor(),
  x = rep(seq_len(3), times = 3),
  y = runif(3 * 3) + .5
)

ggplot(data, aes(x = x, y = y, fill = group)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_lgbtq("pansexual")

Use matching theme_lgbtq() to make colors stand out the most:

ggplot(data, aes(x = x, y = y, fill = group)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_lgbtq("pansexual") +
  theme_lgbtq("pansexual")

theme_lgbtq() passes additional parameters to ggplot2::theme(), so it’s fully customizable:

ggplot(data, aes(x = x, y = y, fill = group)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_lgbtq("pansexual") +
  theme_lgbtq("pansexual", legend.position = "left")

Almost all ggplot2 uses of palette_lgbtq() will be with color and fill scales, so the scale_color_lgbtq() and scale_fill_lgbtq() functions provide a shorthand and more descriptive notation; there’s nothing stopping you, however, from passing them manually or using in any other package, though the ggplot2 dependency might be a pretty large one.

ggplot(data, aes(x = x, y = y, fill = group)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = palette_lgbtq("pansexual")) +
  theme_lgbtq("pansexual", legend.position = "left")

Gallery

Only a few most common palettes are included below. For the complete list, see palette gallery vignette.

palette_lgbtq("rainbow")

palette_lgbtq("philadelphia")

palette_lgbtq("progress")

palette_lgbtq("lesbian")

# In its original meaning of "gay men"
palette_lgbtq("gay")

palette_lgbtq("bisexual")

# Background added to avoid the "disappearance" of the white stripe
print(palette_lgbtq("transgender"), background = "gray92")

palette_lgbtq("asexual")

palette_lgbtq("nonbinary")

palette_lgbtq("intersex")

End notes

I believe in equal rights and treatment for everybody, regardless of their sexuality, gender identity, skin tone, nationality, and other features beyond human control. Thus, I do not allow gglgbtq to be used in any project that promotes hate based on the aforementioned factors.