---
title: "CEMiTool diagnostics"
always_allow_html: yes
output:
  html_document:
     code_folding: hide
     theme: cosmo
     self_contained: true
  pdf_document:
    toc: true
    number_sections: true
---

```{r echo=FALSE, results="asis", cache=FALSE, label=title}
cat("#", title, "{.tabset}")
```

## Sample clustering
```{r echo=FALSE, cache=FALSE, fig.align="center", label=sample_tree_plot}

	if(inherits(cem@sample_tree_plot, "grob")){
	    grid::grid.draw(cem@sample_tree_plot)	
	}else{
        writeLines("Please create sample tree plot!")
    }    
```

## Mean Variance 
```{r echo=FALSE, cache=FALSE, fig.align="center", label=mean_var_plot}

    if(inherits(cem@mean_var_plot, "gg")){   
        print(cem@mean_var_plot)
    }else{
        writeLines("Please create mean variance plot!")
    }
```

## Quantile-quantile plot
```{r echo=FALSE, cache=FALSE, fig.align="center", label=qq_plot}

    if(inherits(cem@qq_plot, "gg")){
	    print(cem@qq_plot)
    }else{
        writeLines("Please create quantile-quantile plot!")
    }
```

## Expression histogram
```{r echo=FALSE, cache=FALSE, fig.align="center", label=hist_plot}

    if(inherits(cem@hist_plot, "gg")){
        print(cem@hist_plot)
    }else{
        writeLines("Please create expression histogram!")
    }  	  
```

## Beta x R2 plot
```{r echo=FALSE, cache=FALSE, fig.align="center", label=beta_r2_plot}

	error_if_s4 <- tryCatch(cem@beta_r2_plot[[1]],
							error=function(e) e)
	if(inherits(error_if_s4, "error")){
		writeLines("### Please create Beta x R2 plot!")
	}else{
		print(cem@beta_r2_plot[[1]])
	}
```

## Mean connectivity plot
```{r echo=FALSE, cache=FALSE, fig.align="center", label=mean_k_plot}
   
	error_if_s4 <- tryCatch(cem@mean_k_plot[[1]],
							error=function(e) e)
	if(inherits(error_if_s4, "error")){
		writeLines("### Please create mean connectivity plot!")
	}else{
		print(cem@mean_k_plot[[1]])
	}
```
