Reputation: 2262
I have the following example data:
d <- data.frame(x = 1:3, y = 1:3, category = letters[1:3], p = c(TRUE, TRUE, FALSE))
I'd like to plot this coloring by category.
ggplot(d, aes(x, y, color = category) + geom_point(shape = "circle filled")
Then I'd like to make the fill:
p
is TRUE
ggplot(d, aes(x, y, color = category, fill = ???) + geom_point(shape = "circle filled")
Has anyone any suggestions?
Could I
Upvotes: 1
Views: 913
Reputation: 173793
You can use fill = after_scale(color)
to assign the fill to the same value as the color scale. Using after_scale(ifelse(p, color, "white")
should give you the optional white fill value instead.
The only minor snag is that the usual NSE we get inside aes
doesn't work inside after_scale
, so we need to use d$p
instead of just p
for the first argument of ifelse
ggplot(d, aes(x, y, color = category)) +
geom_point(aes(fill = after_scale(ifelse(d$p, color, "white"))),
shape = "circle filled", size = 10)
Upvotes: 2