3 # https://mp.weixin.qq.com/s/FZWinr14RTs6YSUE_juaug
9 Phylum
=c("Ruminococcaceae","Bacteroidaceae","Eubacteriaceae","Lachnospiraceae","Porphyromonadaceae"),
10 GroupA
=c(37.7397,31.34317,222.08827,5.08956,3.7393),
11 GroupB
=c(113.2191,94.02951,66.26481,15.26868,11.2179),
12 GroupC
=c(123.2191,94.02951,46.26481,35.26868,1.2179),
13 GroupD
=c(37.7397,31.34317,222.08827,5.08956,3.7393)
16 df
.long
<- df
%>% gather(group
, abundance
, -Phylum
)
21 arrange(by
=desc(Phylum
)) %>%
22 mutate_if(is
.numeric
, cumsum
)
24 link_dat
<- link_dat
[, c(1,2,rep(3:(ncol(link_dat
)-1),each
=2), ncol(link_dat
))]
25 link_dat
<- data
.frame(y
=t(matrix(t(link_dat
[,-1]), nrow
=2)))
26 link_dat$x
.1 <- 1:(ncol(df
)-2)+bar
.width
/2
27 link_dat$x
.2 <- 1:(ncol(df
)-2)+(1-bar
.width
/2)
29 p
<- ggplot(df
.long
, aes(x
=group
, y
=abundance
, fill
=Phylum
)) +
30 geom_bar(stat
= "identity", width
=bar
.width
, col
='black') +
31 geom_segment(data
=link_dat
, aes(x
=x
.1, xend
=x
.2, y
=y
.1, yend
=y
.2), inherit
.aes
= F)
33 pdf(file
="linkedSegments.pdf")