Сопряжение образцов со скрипкой сюжета в R - PullRequest
2 голосов
/ 26 сентября 2019

Я пытаюсь воспроизвести этот график из ggpaired (ggpubr), но на графике скрипки вместо boxplot:

before <-c(200.1, 190.9, 192.7, 213, 241.4, 196.9, 172.2, 185.5, 205.2, 193.7)
after <-c(392.9, 393.2, 345.1, 393, 434, 427.9, 422, 383.9, 392.3, 352.2)

 d <- data.frame(before = before, after = after)
 ggpaired(d, cond1 = "before", cond2 = "after",
     fill = "condition", palette = "jco")

Я пробовал использовать geom_violin из ggplot2, но безуспешно при сопряжении образцов, таких какggpaired делает

paired boxplot

1 Ответ

2 голосов
/ 26 сентября 2019

Сначала необходимо изменить данные:

library(ggplot2)
before <-c(200.1, 190.9, 192.7, 213, 241.4, 196.9, 172.2, 185.5, 205.2, 193.7)
after <-c(392.9, 393.2, 345.1, 393, 434, 427.9, 422, 383.9, 392.3, 352.2)

d <- data.frame(before = before, after = after)
d$obs <- 1:nrow(d)
d2 <- tidyr::gather(d, time, value, -obs)

ggplot(d2, aes(time, value)) + 
  geom_violin() +
  geom_point() +
  geom_line(aes(group = obs)) +
  scale_x_discrete(limits = c('before', 'after'))

enter image description here

...