Skip to content

Latest commit

 

History

History
69 lines (54 loc) · 2.7 KB

Script described.md

File metadata and controls

69 lines (54 loc) · 2.7 KB

Bubble bar in R Studio

This graph is part of a research project from a spent fuel nuclear pond

Input file

The input file is a table where the relative abundance of genera (calculated in Excel) in 10 samples is represented. An additional column represents the condition indoor or outdoor

The input was created and manipulated in Excel (to calculate the average relative abundance) and then saved as a CSV file. Here is a table of the input file:

Screenshot 2023-08-03 at 14 21 09

Library required

library(ggplot2)
library(reshape2)
library(tidyr)
library(dplyr)

Read file

pc = read.csv("phylaT.csv", header = TRUE)

Change to long format

pcm = melt(pc, id = c("Samples", "Condition"))

Keep the same order (Optional)

In this particular case, I added this step to keep the order set on the columns to show the abundance of others at the bottom of the graph

pcm$Sample <- factor(pcm$Sample,levels=unique(pcm$Sample))

Create the graph

xx = ggplot(pcm, aes(x = Sample, y = variable)) + 
  geom_point(aes(size = value, fill = Condition), alpha = 0.75, shape = 21) + 
  scale_size_continuous(limits = c(0.000001, 100), range = c(1,10), breaks = c(1,10,50,75)) + 
  labs( x= "", y = "", size = "Relative Abundance (%)", fill = "Condition")  + 
  theme(legend.key=element_blank(), 
        axis.text.x = element_text(colour = "black", size = 12, face = "bold", angle = 90, vjust = 0.3, hjust = 1), 
        axis.text.y = element_text(colour = "black", face = "bold", size = 9), 
        legend.text = element_text(size = 10, face ="bold", colour ="black"), 
        legend.title = element_text(size = 11, face = "bold"), panel.background = element_blank(), 
        panel.border = element_rect(colour = "black", fill = NA, size = 1.2), 
        legend.position = "right", panel.grid.major.y = element_line(colour = "grey95")) +  
  scale_fill_manual(values = c("pink", "green"), guide = guide_legend(override.aes = list(size=5))) + 
  scale_y_discrete(limits = rev(levels(pcm$variable)))

See the graph

xx

Save the file as png

In some versions of R Studio, it is possible to export the graph as PDF or JPG, however, in my particular case the quality is not the best, hence I saved the file with the following script:

ggsave("Bubble_plot_more.png", width = 8, height = 6, dpi = 300)

Result graph

This is the resulting graph. Feel free to change the settings

Screenshot 2023-08-03 at 14 20 12