0
votes

I'm trying to create a grouped scatter plot which looks like this (with addition of different categories for each group): enter image description here

while I can make something equivalent using seaborn which can handle categorical variables too(https://seaborn.pydata.org/examples/scatterplot_categorical.html), I'm not sure how can I represent categorical variables in ggplot2. This is somewhat similar to previous question (How to add 4 groups to make Categorical scatter plot with mean segments?) but each groups has categories too in my case. This is how my data looks in wide form (with columns as groups and last column describing the category for rows):

    BL_CA_1 BL_CA_2 BL_CA_3 CA_BL_1 CA_BL_2 CA_BL_3 BL6_1   BL6_2   BL6_3   CA_1    CA_2    CA_3    Catagory    
BL6_0   -0.656576   -0.930668   -0.56313    -0.798757   -1.28959    -0.99541    -0.154347   0.0172292   -0.0737639  -0.851593   -1.20257    -1.14919    mono:plus   
BL6_1   3.57263 3.49639 3.4982  3.66428 3.72131 3.72738 4.30273 4.2434  4.34975 2.93424 2.91043 2.93532 mono:minus  
BL6_2   5.20641 5.07323 5.05197 5.21741 5.24606 5.23684 5.40763 5.37346 5.43318 5.02805 5.00924 4.91372 mono:plus   
BL6_3   5.20645 5.32332 5.36965 5.19996 5.1646  5.17797 6.26934 6.30538 6.29584 -2.17544    -1.70483    -1.77652    mono:minus  
CAST_1  3.4924  3.57383 3.6345  3.66375 3.65961 3.72133 5.02467 5.27127 5.2847  0.226526    0.0656529   0.363539    mono:plus   
CAST_2  2.06141 2.13846 2.0506  2.02542 2.09087 2.1134  2.50185 2.58112 2.48791 1.57613 1.70318 1.67168 mono:plus   
CAST_3  -11.5074    -12.2199    -10.9278    -11.135 -11.63  -1.51775    -1.12501    -12.1658    -11.6888    -12.3539    -12.0911    -12.5457    bi:plus-minus   
1

1 Answers

0
votes

You can try this

library(tidyverse)
library(ggbeeswarm)
d %>%
  as.tibble() %>% 
  gather(k, v, -Catagory) %>% 
  ggplot(aes(k, v)) + 
    geom_boxplot() +
    geom_beeswarm() + 
    facet_grid(~Catagory) +
    theme(axis.text = element_text(angle=45, hjust = 1))

enter image description here