在 R 中的 ggplot2 上使用 ConnLines

问题描述

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

@H_404_6@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,axis.text.x = element_text(angle = 45,vjust=1.1,hjust=1.1),legend.title = element_text(size=6,face = "bold",legend.text = element_text(size=6,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")

抛出以下错误

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

taxa_new 是分组数据框,因为 ggplot 要求这样做。将其转换为 ConnLines 内的矩阵也不起作用。在没有 ConnLines 的情况下,绘图工作正常。我认为 ConnLinesggplot2 不兼容,仅适用于 barplot

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)