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.
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:
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:
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.
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"))
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.
Log in to answer this question.