1

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.

Sylvia Rodriguez
  • 1,203
  • 2
  • 11
  • 30

1 Answers1

2

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
)
jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • That's awesome! Thank you so much! Is it also possible to make the diamond larger? I tried inserting ```cex = c(10, rep(1, 25))```, but then an error occurs: ```the parameter "cex" must have length 1```. – Sylvia Rodriguez Aug 04 '20 at 05:31
  • 1
    Sorry @sylvia-rodriguez, I don't know how to do that without changing the size of all the points. There may be a way using a variation of `with(df, symbols(x = y, y = z, circles = c(0.01, rep(NA, 25)), add = TRUE))` after the beeswarm plot, but you would need to tweak it for your needs. – jared_mamrot Aug 04 '20 at 10:42
  • Thank you very much. I will try. Otherwise, I can post a new question :) – Sylvia Rodriguez Aug 06 '20 at 22:14