Используйте следующий код
library(tidyverse)
df %>% pivot_longer(cols = -Cl, names_to = "Sig", values_to = "value") %>%
mutate(cl = factor(Cl, levels = c(1, 2, 3))) %>%
ggplot() + geom_violin(aes(cl, value, fill=cl)) + facet_wrap(Sig~.)
If you want to reproduce the plot you have provided use
df %>% pivot_longer(cols = -Cl, names_to = "Sig", values_to = "value") %>%
mutate(cl = factor(Cl, levels = c(1, 2, 3))) %>%
ggplot() + geom_violin(aes(cl, value, fill=cl)) +
facet_wrap(Sig~.) + theme_bw() + coord_flip()
If you don't want to trim
your violin plot then use
df %>% pivot_longer(cols = -Cl, names_to = "Sig", values_to = "value") %>%
mutate(cl = factor(Cl, levels = c(1, 2, 3))) %>%
ggplot(aes(cl, value, fill=cl)) + geom_violin(trim = FALSE) +
facet_wrap(Sig~.) + theme_bw() + coord_flip()
введите описание изображения здесь
Данные
df = structure(list(Cl = c(1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 3L), Sig1 = c(3.5,
2.1, 0.8, 9.1, 10.1, 11.1, 23.5, 21.5, 18.4), Sig2 = c(2.5, 2,
6, 3.6, 8.5, 12.5, 19.7, 20, 11), Sig3 = c(3.7, 1.7, 2.5, 0.23,
4.7, 20, 18, 15.7, 13.9)), class = "data.frame", row.names = c(NA,
-9L))
Ваш Cl
2 не содержит точных копий, которые можно использовать для скрипичного сюжета.