Tuesday, 17 March 2026

Making a bubble plot to show frequencies

I've been using ggplot2 in R to make a bubbleplot, to show frequencies. This is an alternative to a histogram. Here's a little example:

 I have a file year_data_file_example.txt with columns YEAR, LINEAGE, NUMBER, with the number of bacterial isolates of each particular lineage:

YEAR LINEAGE NUMBER
1990 lineage1 30
1990 lineage2 25
1990 lineage3 5
1991 lineage1 25
1991 lineage2 27
1991 lineage3 8
1992 lineage1 20
1992 lineage2 28
1992 lineage3 9 
 
I made a bubbleplot using R by typing: 
> library("ggplot2")
> MyData <- read.table("year_data_file_example.txt",header=TRUE)
> ggplot(MyData, aes(x=MyData$YEAR, y=MyData$LINEAGE, size=MyData$NUMBER)) + geom_point(color = 'blue')
 
Acknowledgements
Thanks to my colleague Amber Barton for advice.
 
 



 

No comments: