## ----echo=FALSE, results="hide", warning=FALSE--------------------------------
suppressPackageStartupMessages({
    library(GOfan)
    library(org.Dr.eg.db)
    library(ggplot2)
})
knitr::opts_chunk$set(
    warning = FALSE, message = FALSE,
    fig.width = 9, fig.height = 9,
    dpi = 72
)
is_bioconductor_build <- function() {
    nzchar(Sys.getenv("IS_BIOC_BUILD_MACHINE"))
}

## ----eval=FALSE---------------------------------------------------------------
# if (!require("BiocManager", quietly = TRUE)) {
#     install.packages("BiocManager")
# }
# 
# BiocManager::install("jianhong/GOfan")

## ----quickstart---------------------------------------------------------------
library(ggplot2)
library(GOfan)
library(org.Dr.eg.db)
## load data
csv <- system.file("extdata", "GO.BP.enrichment.csv", package = "GOfan")
bp <- read.csv(csv, row.names = 1)
head(bp, n = 2)
## build a graph of hierarchical GO term relationships.
g <- getGraph(bp, org = org.Dr.eg.db, onto = "BP")

## ----plotly, eval=!is_bioconductor_build()------------------------------------
## visualization
sunburstGO(bp, g,
    org = org.Dr.eg.db, fill = "qvalue",
    filterNodesByEdgeNumber = 0,
    plotBy = "plotly"
)

## ----plotByggplot2------------------------------------------------------------
sunburstGO(bp, g,
    org = org.Dr.eg.db, fill = "qvalue",
    onlyKeep = c("GO:0099536", "GO:0046903", "GO:0034330"),
    plotBy = "ggplot2"
) +
    scale_fill_continuous(palette = "YlOrRd")

## ----fanplot, eval=FALSE------------------------------------------------------
# sunburstGO(bp, g,
#     org = org.Dr.eg.db,
#     fill = "qvalue", sub_rect = "count",
#     onlyKeep = c("GO:0099536"),
#     plotBy = "ggplot2",
#     fontsize = 2,
#     start = 0, end = pi / 2
# ) +
#     scale_fill_continuous(palette = "YlOrRd")

## ----show-prebuilt-svg, echo=FALSE, out.width="90%", echo=FALSE---------------
knitr::include_graphics(file.path("figures", "sample_plot.svg"))

## ----pressure, echo=FALSE-----------------------------------------------------
sessionInfo()

