Last active
January 10, 2024 23:08
-
-
Save saketkc/18d1a1f96a86d731ce53796955d0d9b7 to your computer and use it in GitHub Desktop.
clusterProfiler inspiredbarplot and dotplot for GOSeq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
barplot <- function(df, showCategory=15){ | |
df <- df[with(df, order(ratio, padj, decreasing = c(TRUE, FALSE))),] | |
df <- head(df, n=showCategory) | |
breaks <- round( c(0, 1/4, 2/4, 3/4, 1) * max(df[['ratio']]) , 2) | |
p_plot <- ggplot(df, aes_string(x="term", y="ratio", fill="padj")) + | |
geom_col() + | |
scale_y_continuous(expand=c(0, 0), breaks=breaks, limits=c(0, max(df[["ratio"]]+0.05))) + | |
scale_x_discrete(name='GO term') + | |
scale_fill_continuous(low="#00dbde", high="#FFF94C") + | |
theme(text=ggplot2::element_text(size=9)) + | |
coord_flip() + | |
theme_bw(base_size=9) | |
return(p_plot) | |
} | |
dotplot <- function(df, showCategory=15){ | |
df <- df[with(df, order(ratio, padj, decreasing = c(TRUE, FALSE))),] | |
df <- head(df, n=showCategory) | |
d_plot <- ggplot(df, aes_string(x="term", | |
y="ratio", | |
colour="padj", | |
size="numDEInCat")) + | |
geom_point() + | |
scale_color_gradient(low="#00dbde", | |
high="#FFF94C") + | |
coord_flip() + | |
theme_bw(base_size=9) | |
return(d_plot) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Saket,
I'd like to use your function with my goseq results data.frame object.
However, I can't understand from where your ratio and padj objects came from.
Did you use the goseq Bioconductor package https://bioconductor.org/packages/release/bioc/html/goseq.html?
Would it be possible to have a quick example on how the function runs with results annotated your way?
Thanks a lot in advance!