plotGO <- function(enrichdf, nrows = 30, orderby=NULL, ont){
require(plotly)
if(!is.data.frame(enrichdf)){
stop("enrichdf should be data.frame")
}
if(!exists("ont") | !(ont %in% c("BP","MF","CC")) ){
stop("A valid value should be provided for 'ont'")
}
dataTitle <- list(BP=c("Biological Process", 'rgb(227,74,51)'),
MF=c("Molecular Function",'rgb(31,119,180)'),
CC=c("Cellular Component", 'rgb(49,163,84)'))
enrichdf <- enrichdf[enrichdf$Ont == ont, ]
if(!is.null(orderby)){
orderby = match.arg(orderby, c("DE", "P.DE", "N", "Term"))
if(orderby=="P.DE" | orderby =="Term"){
enrichdf <- enrichdf %>% arrange(get(orderby))
} else{ enrichdf <- enrichdf %>% arrange(desc(get(orderby)))}
}
p <- enrichdf[1:nrows,] %>%
plot_ly(x=~DE, y=~go_id, text=~Term, type = "bar",
marker = list(color=dataTitle[[ont]][2]),
orientation = "v") %>%
layout(margin = list(l=100), yaxis = list(title=""),
title=dataTitle[[ont]][1])
return(p)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.