0

我正在尝试ggplot2在 R 中的堆叠 barplot ( ) 中绘制几个条之间的连接线。为此,我ConnLines从 DescTools 包中找到了该函数。我的目标是获得类似文档中所示的结果。

taxa_bars <- ggplot(taxa_new, 
                    aes(x=Sample, y=Rel_abund, fill=Kingdom, width=0.5)) + 
  geom_bar(position="fill", stat="identity", color="black") + 
  facet_wrap(~Individual, ncol=4) +
  ConnLines(taxa_new, beside=FALSE) +
  
  theme_bw() + 
  theme(axis.title=element_text(size=12, face="bold", color = "black"),
  axis.text=element_text(size=11, face="bold", color = "black"),
  axis.text.x = element_text(angle = 45, vjust=1.1, hjust=1.1),
  legend.title = element_text(size=6, face = "bold", color = "black"),
  legend.text = element_text(size=6, face = "bold", color = "black"),
  legend.key.size = unit(3, "mm"),
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  panel.background = element_blank(),
  strip.background = element_rect(fill="white", color="white"),
  strip.text = element_text(face="bold", color="black")) +
  labs(x = "", y = "Abundance [%]", fill = "Taxa")

引发以下错误:

Error in barplot.default(..., plot = FALSE) : 'height' must be a vector or a matrix

taxa_new是一个分组数据框,因为 ggplot 要求这样做。将其转换为内部矩阵ConnLines也不起作用。没有ConnLines. 我认为这与 ?ConnLines不兼容ggplot2且仅适用于barplot?

4

0 回答 0