Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to draw connection lines between several bars in a stacked barplot (ggplot2) in R. For this, I found the ConnLines function from the DescTools package. I aim for a similar result as shown in the documentation.

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")

Throws the following error:

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

taxa_new is a grouped data frame, since ggplot demands that. Converting it to a matrix within ConnLines does not do the job either. The plot works fine without the ConnLines. I assume that ConnLines is not compatible with ggplot2 and only works with barplot?

question from:https://stackoverflow.com/questions/66050886/use-connlines-on-ggplot2-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
139 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...