How to construct a multicomponent violin diagram

Hello everyone!

Here's my data style, but I won't build a multicomponent violin diagram:

group Clade Insertion_Time
group2 Tork 853185
group2 Athila 379312
group2 Retand 1130063
group2 Tekay 255525
group2 Athila 239886
group2 Ale 0
group2 Ale 0
group2 Ogre 41610
group2 Athila 431352
group2 TAR 0
group2 Ogre 338127
group2 Retand 372729
group2 Ale 767998
group2 Ale 270223
group2 TAR 36273
group2 Ogre 488782
group2 Tekay 1319446
group2 Angela 473732
group2 Retand 0
group2 Tork 486354
group2 Iva0 1245755
group2 Tekay 255688
group2 Retand 327799
group2 Tork 494165
group2 Tekay 162057
group2 Retand 477599
group2 Ale 190091
group2 Athila 551171
group2 Ogre 1917981
group2 Retand 593767
group2 Tork 93278
group2 Tork 363996
group2 Retand 1781190
group2 Ale 678763
group2 Ale 213280
group2 SIRE 1247590
group2 Ale 0
group2 TAR 731977
group2 Retand 215069
group2 Athila 24889
group2 Ogre 749291
group2 TAR 120068
group2 Athila 0
group2 CRM 2129153
group2 Ogre 215191
group2 Retand 248248
group2 Tekay 255379
group2 Tekay 68154
group2 Tekay 18533
group2 Tork 0
group2 Tekay 415309
group2 TAR 1749697
group2 Athila 27844
group2 Ale 262836
group2 Ale 0
group2 Athila 312612
group2 Ikeros 398434

...

group4 TAR 1823419
group4 SIRE 0
group4 Ale 252485
group4 Retand 1042084
group4 Athila 0
group4 Athila 361713
group4 Athila 74877
group4 Ale 287386
group4 Retand 666031
group4 Athila 1248786
group4 Iva0 299702
group4 TAR 51742
group4 Athila 54880
group4 Athila 119843
group4 Athila 481182
group4 Tekay 213428
group4 TAR 572446
group4 SIRE 66218
group4 Retand 188692
group4 Retand 212497
group4 Iva0 176565
group4 Tork 850561
group4 Ogre 1327321
group4 Tekay 103632
group4 CRM 212104
group4 Bianca 0
group4 Ogre 69321
group4 Ale 1762144
group4 CRM 1354523
group4 Retand 254490
group4 Tekay 48177
group4 Tekay 0
group4 CRM 0
group4 Retand 50853
group4 Ale 276042
group4 Ale 219363
group4 Athila 221896
group4 CRM 0
group4 Ale 148884
group4 Angela 28026
group4 Tork 0
group4 Athila 129182
group4 Angela 206045
group4 TAR 238769
group4 CRM 1364136
group4 Iva0 281428
group4 Tork 723907
group4 Ikeros 78280
group4 Retand 0
group4 Tekay 0
group4 Tork 303646
group4 Ikeros 394351
group4 Athila 170561
group4 Tork 0
group4 Tork 245240
group4 SIRE 370867
group4 Athila 0
group4 CRM 409171
group4 Retand 918903
group4 Galadriel 2588420
group4 Ogre 170991
group4 Iva0 352595
group4 Athila 357830
group4 Athila 350554
group4 Ogre 54452
group4 TAR 423770
group4 TAR 123539
group4 Ogre 2004199
group4 Athila 0
group4 Tork 1556622
group4 Tekay 20487
group4 Athila 641308
group4 Athila 24338
group4 Ogre 0
group4 Ikeros 83733
group4 SIRE 164272
group4 Athila 57505
group4 Athila 28760
group4 Athila 274858
group4 Ikeros 1182380
group4 Tekay 645533
group4 Tekay 345856
group4 Tekay 250372
group4 Ogre 554278
group4 Ale 0
group4 SIRE 99987
group4 Tekay 329297
group4 Ale 1113891
group4 Ogre 729401
group4 Tork 795808
group4 Ale 854765
group4 Ale 229850
group4 Ogre 31034
group4 Ogre 1656153
group4 Ale 0
group4 Ale 0
group4 CRM 0
group4 Athila 115298
group4 Ale 173772
group4 Athila 0
group4 TAR 830165
group4 Ikeros 337138
group4 Retand 301111
group4 Iva0 0
group4 Ogre 1328958
group4 Iva0 2205055
group4 TAR 274075
group4 Ogre 138328
group4 Retand 0
group4 Tekay 191620
group4 Athila 19843
group4 Athila 318665
group4 Athila 140713
group4 Tork 424606
group4 Ale 1357715
group4 Retand 2887027
group4 Ale 725725
group4 Tork 70919
group4 Ogre 634225
group4 Retand 303966
group4 Retand 210941
group4 Ale 1602976
group4 Athila 30590
group4 Athila 2345184
group4 Athila 508315
group4 Athila 1189707
group4 Ale 656552
group4 Ale 442945
group4 Iva0 143336
group4 Ale 288463
group4 Ogre 0
group4 CRM 329910

...

The number of groups varies from group to group. The final build should look something like this:

图片

I will build a violin diagram for the individual groups, with the code listed below. But I don't know how to fuse the components together.

library(ggplot2)
library(ggsci)
library(hrbrthemes)
library(RColorBrewer)

data <-read.csv("insertion.csv")

insertion.csv

ggplot(data, aes(x = Clade, y = Insertion_Time, col = Clade),
  show.legend = F) +
  geom_violin() +
  geom_boxplot(width = 0.2) +
  geom_jitter(width = 0.2, col = "black") +
  guides(col = F) -> p

p +
  theme( axis.line = element_line(color = "black", size = 0.2),
         axis.title = element_text(size = 12),
         axis.text = element_text(size = 10),
         axis.ticks = element_line(colour = "grey"),
         
         panel.background = element_blank(),
         panel.border = element_rect(fill = NA, size = 0.3),
         panel.grid.major = element_line(linetype = 2, colour = "grey", size = 0.5),
         
         plot.title = element_text(size = 12, hjust = 0.5)) -> p2
p2

Anyone? Thank you!

I have solved the problem.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.