Skip to content

Facet + axis labels #2656

@ldecicco-USGS

Description

@ldecicco-USGS

This could easily be "won't fix" and I totally understand, but I was wondering if this is the expected behavior:

library(ggplot2)
library(dplyr)

starwars <- starwars %>%
  filter(homeworld %in% c("Tatooine","Naboo","Alderaan"),
         eye_color %in% c("blue","brown","hazel")) %>%
  mutate(skin_color = factor(skin_color))

colors <- ifelse(levels(starwars$skin_color) == "fair","red","black")

ggplot(data=starwars) +
  geom_tile(aes(x=name, y=skin_color, fill = mass)) +
  theme_bw() +
  facet_grid(eye_color ~ homeworld, 
             scales="free", space="free") +
  theme(axis.text.x = element_text( angle = 90,vjust=0.5,hjust = 1),
        axis.text.y = element_text(color = colors)) 

image

I would like to see the skin_color "fair" label red and the rest black. I see what's happening: for each eye_color, it uses the vector c("black","red","black","black").

But...I have not figured out a way to say for "brown" eye_color, use c("black","red","black","black"), but for "blue" eye_color, use c("red","black").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions