Plotting a scatter plot with categorical data.

Note that you can adjust how tightly the ggbeeswarm points are packed with the cex=1 argument.

library(tidyverse)
library(palmerpenguins)
library(ggbeeswarm)
library(ggforce)

# peek at penguins data
glimpse(penguins)
#> Rows: 344
#> Columns: 7
#> $ species           <chr> "Adelie", "Adelie", "Adelie", "…
#> $ island            <chr> "Torgersen", "Torgersen", "Torg…
#> $ culmen_length_mm  <dbl> 39.1, 39.5, 40.3, NA, 36.7, 39.…
#> $ culmen_depth_mm   <dbl> 18.7, 17.4, 18.0, NA, 19.3, 20.…
#> $ flipper_length_mm <dbl> 181, 186, 195, NA, 193, 190, 18…
#> $ body_mass_g       <dbl> 3750, 3800, 3250, NA, 3450, 365…
#> $ sex               <chr> "MALE", "FEMALE", "FEMALE", NA,…

ggplot(data = penguins) +
  aes(y = body_mass_g, x = species) +
  geom_beeswarm(cex = 0.5) +
  coord_flip()
#> Warning: Removed 2 rows containing missing values
#> (position_beeswarm).


ggplot(data = penguins) +
  aes(y = body_mass_g, x = species) +
  geom_beeswarm(cex = 1.5) +
  coord_flip()
#> Warning: Removed 2 rows containing missing values
#> (position_beeswarm).


ggplot(data = penguins) +
  aes(y = body_mass_g, x = species) +
  geom_beeswarm(cex = 2.5) +
  coord_flip()
#> Warning: Removed 2 rows containing missing values
#> (position_beeswarm).

Created on 2020-06-11 by the reprex package (v0.3.0)

1 Like