1

Is it possible to draw a beeswarm plot such that point-wise colors are aligned in the horizontal center? (I believe this would improve the readability a lot especially if the data is not as clear-cut as in the example.)

To achieve this plot with centered colors:

beeswarm(breast$time_survival, pch = 16, pwcol = 1 + breast$event_survival, method='center')

I tried:

beeswarm(breast$time_survival, pch = 16, method='center')
beeswarm(breast[breast$event_survival==1,]$time_survival, pch = 16, col=2, method='center', add=T)

It's close, but the individual points on the individual plots are not precisely the same.

Felix Dietrich
  • 127
  • 1
  • 11

1 Answers1

0

I think you were on the right track. Here's one approach:

data(breast)

## Create a blank plot with appropriate limits and axes
beeswarm(breast$time_survival, pch = NA)

## Split the data into two groups
x0 <- breast$time_survival[breast$event_survival == 0]
x1 <- breast$time_survival[breast$event_survival == 1]

## Add each group separately
beeswarm(x0, pch = 16, method='center', side =  1, col = 1, at = 1 + xinch(0.04), add = TRUE)
beeswarm(x1, pch = 16, method='center', side = -1, col = 2, at = 1 - xinch(0.04), add = TRUE)

The key parameter is "side", which forces the swarms to expand in only one direction.

For the "at" parameter, I used "xinch(0.04)" because this is half of the default space between points (assuming you haven't changed cex or spacing).