How do I create a plot that is half box plot and half beeswarm in R?

194 Views Asked by At

I'm using this link currently to create a right-sided beeswarm plot: https://r-charts.com/distribution/beeswarm/. I want to add a box plot to the left side of the beeswarm plot to create a plot that looks like this Nature one. Nature plot

Does anyone know how I would be able to do this?

I tried using geom_half_plot() in package gghalf, but this ruins the beeswarm side by making the dots look cluttered. This is the code I used:

ggplot(data, aes(group = data , x = data$A, y = data$B)) +
  geom_half_boxplot() +
  geom_beeswarm(beeswarmArgs = list(side = 1))

Geom Half Plot

Is there a way to fix this issue?

1

There are 1 best solutions below

0
On

what about:

library(gghalves)
library(ggbeeswarm)

iris |>
  ggplot(aes(x = Species, y = Sepal.Length)) +
  geom_half_boxplot() +
  geom_beeswarm(aes(x = as.integer(Species) +
                    .2 ## adapt offset as fit
                ))

beeswarm plot with horizontal offset