Customise r beeswarm plot

273 Views Asked by At

I am using the beeswarm package in R and have some problems customizing individual datapoints. I am using below data and code.

 library(beeswarm)
 df <- data.frame(x = c(LETTERS), y = "1", 
 z = c(rnorm(26, 11, 4)))
 beeswarm(z ~ y, data = df,
     pwcol = c(1, rep(2, 25)), pwpch = c(1, rep(2, 25)), corral = "wrap", method = "center", 
     xlab = "", ylab = "variable", las=1
     )

I would like to change this so that:

  1. The individual black circle becomes a black diamond with red fill.
  2. All red triangle datapoints become dark grey circles with no fill (open).

Could anyone help, please? Thank you.

1

There are 1 best solutions below

3
On BEST ANSWER

You're almost there, you just need a couple of minor changes:

library(beeswarm)
df <- data.frame(x = c(LETTERS), y = "1", 
                 z = c(rnorm(26, 11, 4)))
beeswarm(z ~ y, data = df,
         pwcol = c("black", rep("grey15", 25)),
         pwpch = c(23, rep(1, 25)),
         pwbg = c("red", rep("transparent", 25)),
         corral = "wrap", method = "center", 
         xlab = "", ylab = "variable",
         las=1
)