```{r "{{funsys}}_plots_ora", echo=FALSE, results='asis', message=FALSE, warning=FALSE}
n_category <- 30
default_width <- set_default_width(enrich_obj = enrich_obj, showCategory=n_category)

if(! exists("attr_vector")) attr_vector <- NULL
# Add main label
cat("## **{{funsys}} - Over Representation Analysis**\n",
		"The ORA method takes a group of significant genes and performs a Fisher's exact test for each term of the selected functional category.\n\n"
)

cat(
	"**Barplot**\n\n", 
	"The most highly signficant categories in ascending order, according to adjusted p-value. 
	The x-axis represents the number of significant genes found within the functional category.\n\n"
)
go_pp <- graphics::barplot(enrich_obj, showCategory=n_category)
invisible(plot_in_div(go_pp, fig_width = default_width))

cat("\n\n**Dotplot**\n\n",
        "The most highly signficant categories in descending in categories of gene ratio, defined as the proportion of significant genes that are found in the functional category.
         The x-axis represents the gene ratio and the dot size the number of genes associated with the functional category.\n\n"
)
go_pp <- enrichplot::dotplot(enrich_obj, showCategory=n_category)
invisible(plot_in_div(go_pp, fig_width = default_width))


if (!is.null(attr_vector)){
	cat("\n\n**Distributions of ",gene_attribute_name,"**\n\n", 
	  "This plot shows the distribution of gene ",gene_attribute_name," that enriched the top enriched functional term/pathways.
	   The X axis repressent the distribution values. The color of the distribution repressents the FDR of the enrichment.
	   The vertical lines represents the first, second and third quartiles.\n\n"
	)

	density_pp <- enrich_density(enrich_obj, attributes = attr_vector, showCategory = n_category) + 
	ggplot2::labs(x = gene_attribute_name, y = NULL, fill = "Enrichment\nFDR") +
	ggplot2::scale_fill_gradient2(low = "#3838F3", high = "#F33838", mid = "white",na.value = "#50EA55", midpoint = pvalcutoff)
	invisible(plot_in_div(density_pp, fig_width = default_width))
}

cat("\n\n**Gene-Concept Network**\n\n", 
	  "The network connects the top functional categories (brown nodes) to their associated genes (grey or colored nodes).
 	   The size of the functional category nodes shows the number of connected genes.\n\n"
)
if(length(get_genes(enrich_obj)) <= max_genes){
	go_pp <- enrichplot::cnetplot(enrich_obj, showCategory=n_category, foldChange=attr_vector) +
	 		 { if(!is.null(attr_vector)) ggplot2::scale_color_gradient2(name = gene_attribute_name, low = "#0000BF", high = "#bf0000", na.value = "#50EA55") }
	invisible(plot_in_div(go_pp, fig_width = 15, fig_height = 15))
}else{
	cat("\n\nMore than", max_genes, "genes were found among the enriched genes. Only the first", max_genes, "genes belonging to the most significant categories are shown plotted. \n\n")
	enrich_obj_maxed <- force_max_genes_enrobj(enrich_obj, maxGenes=max_genes, showCategory=n_category)

	go_pp <- enrichplot::cnetplot(enrich_obj_maxed, showCategory=n_category, foldChange=attr_vector) +
	 		 { if(!is.null(attr_vector)) ggplot2::scale_color_gradient2(name = gene_attribute_name, low = "#0000BF", high = "#bf0000", na.value = "#50EA55") }
	invisible(plot_in_div(go_pp, fig_width = default_width))
}

cat("\n\n**Enrich Map plot**\n\n", 
  "The top functional categories (nodes), connected if they share genes. Edge thickness represents the number of shared genes.
	  Nodes size represents the number of significant genes within the category.\n\n"
)

if (nrow(as.data.frame(enrich_obj)) > 2) {
	go_pp <- enrichplot::emapplot(enrich_obj, showCategory=n_category,  min_edge = 0.0000000000000001)
	invisible(plot_in_div(go_pp, fig_width = default_width))
} else {
	cat("\nThis graph can not be plotted because fewer than two functional categories were enriched\n")
}
cat("\n\n**Heatplot**\n\n", 
	  "Significant genes (x-axis) and the functional categories in which they appear." 
)
go_pp <- enrichplot::heatplot(enrich_obj, showCategory=n_category, foldChange=attr_vector)
width_size <- calc_width(enrich_obj)
height_size <- calc_height(enrich_obj) 
invisible(plot_in_div(go_pp, height_size, width_size))

cat("\n\n**Upsetplot**\n\n", 
	  "Genes are clustered according to shared enriched categories. 
	  The y-axis shows the number of genes belonging to the different clusters (top) and categories to which they belong (bottom).\n\n"
)
if (nrow(as.data.frame(enrich_obj) > 1)){ # Needs, at least, two categories
	go_pp <- enrichplot::upsetplot(enrich_obj, n=n_category)
	invisible(plot_in_div(go_pp, fig_width = default_width))
	cat("\n \n")
}else{
	cat("\n\nGenes has been enriched in less than 2 categories, so Upsetplot cannot be printed\n\n")
}
```
