In my plot I would like to alter both the color of the points and the color of the labels on those points. I can control the color of points and labels independently, but in the same plot this breaks down. I have provided code for all three scenarios.
library(dplyr)
library(ggplot2)
ds <- 
  mtcars %>% 
  count(cyl, vs) %>% 
  mutate(
    label_color = case_when(
      n > median(n) ~ "black",
      TRUE ~ "white")
  ) 
# Works
ds %>% 
  ggplot(aes(x = as.character(vs), y = cyl, size = n, color = n, label = n)) + 
  geom_point() + 
  geom_text(aes(color = label_color)) + 
  scale_color_identity() #+
  #scale_color_gradient(low = "red", high = "blue") 
# Works
ds %>% 
  ggplot(aes(x = as.character(vs), y = cyl, size = n, color = n, label = n)) + 
  geom_point() + 
  geom_text(aes(color = label_color)) + 
  #scale_color_identity() +
  scale_color_gradient(low = "red", high = "blue") 
# Fails
ds %>% 
  ggplot(aes(x = as.character(vs), y = cyl, size = n, color = n, label = n)) + 
  geom_point() + 
  geom_text(aes(color = label_color)) + 
  scale_color_identity() +
  scale_color_gradient(low = "red", high = "blue") 
