geom_beeswarm and manually set colors (scale_fill_manual)

Viewed 811

I'm making a beeswarm plot with the ggbeeswarm package (with geom_beeswarm()), and I want to MANUALLY fill the points with colors according to the factor levels in a factor variable. Also, I want to set the color around the points (to white).

Setting colors to fill = [FACTOR] inside aes() works fine; the points have different fill colors, and I can set the color of the line around the point to white like this geom_beeswarm(color = "white") (see code chunk #1 below). But when I want to manually set the fill color with scale_fill_manual, the color = "white" command in geom_beeswarm() seems to override it (see code chunk #2 below).

How can I a) set colors manually and b) color the line around my points white?

(All of this works fine with geom_point(), but I like geom_beeswarm() better.)

Here's some dummy data and code that illustrates it all:

# Provide minimal dataframe
x <- c(rep(c("A", "B"), 10))
y <- (rnorm(20, 2, 1))
z <- c(rep(c("Treatment", "Zero"), 10))

df <- data.frame(x, y, z)

# Draw beeswarm plot
library(ggbeeswarm)

# Works fine: (code chunk #1)
ggplot(df, aes(x, y, fill = z)) +
  geom_beeswarm(color = "white",
            pch = 21)

# Does not work fine: (code chunk #2)
ggplot(df, aes(x, y, fill = z)) +
   geom_beeswarm(color = "white") +
     scale_shape_manual(values=c(21, 21)) +
     scale_fill_manual(values=c("#104E8B", "#72bcd4"))


   
0 Answers
Related