0

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?

divsan
  • 1
  • 1
  • Welcome to SO, divsan! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jul 07 '23 at 19:56
  • 1
    The right side doesn't look like a beeswarm. See if https://stackoverflow.com/a/49338481/3358272 helps at all. (I think `gghalves` is going to be very useful.) – r2evans Jul 07 '23 at 20:02
  • Perhaps have a look at the `gghalves` package. – Axeman Jul 07 '23 at 20:03

1 Answers1

0

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

I_O
  • 4,983
  • 2
  • 2
  • 15