3

Dear community members:

In this article the following figure (Figure 3) is found:

figure

It is a type of nested bubble plot combined with tables, for a hierarchy of different taxonomic ranks. It extends from phylum to class to order, showing the relative abundances (%) for each classification.

In the method section, the only reference to R code that I could find was the use of vegan package in some analyses. I fail to find a description of how the figure was created.

I am wondering how can I recreate such kind of plot for my data. Could someone direct me into the right direction?

Henrik
  • 65,555
  • 14
  • 143
  • 159
  • 4
    Have you tried emailing the authors? Chances are they know how to generate the plot (though they might not have used R for it). – Konrad Rudolph Jan 05 '22 at 09:51
  • 2
    Did you check https://www.r-graph-gallery.com/ for inspiration? I would send a mail to the authors by the way. – Felix Phl Jan 05 '22 at 09:56
  • This looks like a combination of ggtree and phylobase . See: https://yulab-smu.top/treedata-book/chapter9.html and https://phylobase.r-forge.r-project.org/ – user12256545 Jan 12 '22 at 12:29

1 Answers1

4

Something like this should be a decent starting point... I think. It's not perfect, but should get you on the way to doing what you want.

library(reshape)
library(ggplot2)
library(data.table)
#library(ggExtra)
library(gridExtra)

#  base code was taken from here and modified
# https://stackoverflow.com/questions/54638898/how-to-plot-proportion-data-with-a-bubble-plot-in-r
# 
# code also taken from here (to reduce spacing)
# https://stackoverflow.com/questions/15556068/removing-all-the-space-between-two-ggplots-combined-with-grid-arrange

Species <- as.character(c(1:12))
name1 <-as.numeric(c(0.17,0.011,0.022,0.003,0.51,0.1,0.01,0.03,0.004,0.06,0.07,0.01))
name2<-as.numeric(c(0.197,0.005,0.027,0.01,0.337,0.157,0.008,0.038,0.017,0.17,0.032,0.002))
data<-as.data.frame(cbind(Species,name1,name2))
data$name1 <- as.numeric(as.character(data$name1)); 
data$name2 <- as.numeric(as.character(data$name2))
data2<-melt(data)

# gets a roughly similar sort of plot 
p <-  ggplot2::ggplot(data2,aes(x=variable, y=factor(Species, levels=unique(Species))))+
  geom_point(aes(size=value))+
  labs(y="Prey Items",x="Species")+
  theme_classic() +
  scale_size_area( limits = c(0,1),max_size = 20) +
        
  #geom_richtext(position='identity',aes(label=Species), fill="grey", hjust = +2.5)
  geom_richtext(position='identity',
                aes(x='name1',label=factor(Species),
                    width = unit(0.01, "npc")),
                hjust = 3.0,
                fill="grey") +
  
  # remove the y axis and the x axis ticks
  theme(axis.line =element_blank(),
        axis.title.y  = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.y=element_blank(),
        plot.margin=unit(c(1,1,1,1), "cm"),
        legend.position = "none") 

# shows the first graph
p

# create new data with additional variables (more species??)
Species <- as.character(c(13:18))
name1 <-as.numeric(c(0.17,0.011,0.022,0.003,0.51,0.1))
name2<-as.numeric(c(0.197,0.005,0.027,0.01,0.337,0.157))
data4<-as.data.frame(cbind(Species,name1,name2))
data4$name1 <- as.numeric(as.character(data4$name1)); 
data4$name2 <- as.numeric(as.character(data4$name2))
data4<-melt(data4)

# combine the data for a full set
data5 = rbind(data2, data4)

# plot the second figure 
p2 <-  ggplot2::ggplot(data5,aes(x=variable, y=factor(Species, levels=unique(Species))))+
  geom_point(aes(size=value))+
  labs(y="Prey Items",x="Species")+
  theme_classic() +
  scale_size_area( limits = c(0,1),max_size = 20) +
  
  #geom_richtext(position='identity',aes(label=Species), fill="grey", hjust = +2.5)
  geom_richtext(position='identity',
                aes(x='name1',label=factor(Species),
                    width = unit(0.01, "npc")),
                hjust = 3.0,
                fill="grey") +
  
  # remove the y axis and the x axis ticks
  # the plot margin changes the horizzontal space between the second plot and first 
  theme(axis.line =element_blank(),
        axis.title.y  = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.y=element_blank(),
        plot.margin=unit(c(1,1,1,-3), "cm"))  


# shows the second graph
p2 

# combine the plots into one (expand the display if it looks iffy in R/Rstudio)
grid.arrange(p,p2, ncol=2)
thehand0
  • 1,123
  • 4
  • 14