An issue in creating a bubble plot using ggplot2
1
0
Entering edit mode
3.4 years ago
f.finamore • 0

Dear all,

I would like to ask you a basic question concerning the creation of a bubble plot for GO term visualization. I have the table structure as follows:

Table structure

while generating a bubble plot using ggplo2 library I do not manage to cluster GO terms that belong to the same group. The script I am using is the following:

library(ggplot2)
library(forcats)  
ggplot(data, aes(y = reorder(GO_term, as.numeric(Class)), x = pValue, size = GeneNumber)) + geom_point(aes(color = Class), alpha = 1.0) +
geom_tile(aes(width = Inf, fill = Class), alpha = 0.2) + 
scale_fill_manual(values = c("red", "yellow", "green", "blue", "purple", "pink"))

The final graph I obtain is the one showed below:

Bubble plot

As you can clearly see, the group1 is splitted by the group6. Moreover, if I increase the number of GO terms to show, this issue occurs several times (several groups are splitted by other groups). May be it is a simple task or may be not, but now I am completely stucked on this. Please, could you give me some help to solve this issue?

Thanks in advance.

blubbleplot ggplot2 issue • 1.1k views
ADD COMMENT
2
Entering edit mode
3.4 years ago
Nitin Narwade ★ 1.6k

I assume your data is always be sorted by class (if not you should sort it first) and then try to convert GO_term to factors by assigning unique GO_term as the levels and this trick should do the job.

library(ggplot2)
library(forcats)  
rm(list = ls())

data <- read.csv("input.tsv", sep ="\t", header = TRUE, stringsAsFactors = FALSE)
data$Class = factor(data$Class, levels = unique(data$Class))
data = data[order(data$Class),]
data$GO_term <- factor(data$GO_term, levels = data$GO_term)

theme_set(theme_bw())
ggplot(data, aes(y = reorder(GO_term, as.numeric(Class)), x = pValue, size = GeneNumber)) + geom_point(aes(color = Class), alpha = 1.0) + geom_tile(aes(width = Inf, fill = Class), alpha = 0.2) + scale_fill_manual(values = c("red", "yellow", "green", "blue", "purple", "pink"))

Sample Output

ADD COMMENT
0
Entering edit mode

Great! Thank you so much! It now works perfectly! It never occurred to me to convert the "GO_term" to factors through "levels". Good idea.

Many thanks again.

ADD REPLY

Login before adding your answer.

Traffic: 2560 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6