https://github.com/broadinstitute/cdsr_plots

https://github.com/broadinstitute/cdsr_plots

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.3%) to scientific vocabulary
Last synced: 6 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: broadinstitute
  • Language: R
  • Default Branch: master
  • Size: 1.04 MB
Statistics
  • Stars: 0
  • Watchers: 18
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created almost 6 years ago · Last pushed over 5 years ago
Metadata Files
Readme

README.Rmd

---
title: "cdsrplots"
output:
  github_document:
  html_notebook:
    theme: united
  html_document:
    theme: united
editor_options: 
  chunk_output_type: inline
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE, fig.width = 7, fig.height = 5, cache = T)

library(tidyverse)
library(useful)
library(taigr)

gene_sets <- cdsrgsea::load_gene_sets()
```

cdsrplots contains standard CDS plots and themes.

## Install

```{r, eval = FALSE}
library(devtools)
devtools::install_github("broadinstitute/cdsr_plots")
```

The package can then be loaded by calling

```{r, eval=FALSE}
library(cdsrplots)
```

## Functions

* Plotting
  * make_volcano
  * make_gsea_dot
  * make_gsea_bar
* Theme
  * theme_publication
  * scale_fill_publication
  * scale_color_publication

## Volcano plot

The `make_volcano` function is a quick and easy tool to visualize results from differential expression/dependency analyses and can be easily customized.

### Example data

As an example we will load the results of a differential expression anlyses comparing Nutlin treated cells to DMSO treated cells.

```{r}
nutlin <- read_csv("./nutlin.csv")
nutlin %>% head()
```

### Base plot

Make a simple plot by providing the data frame and variable names for effect size and significance.

```{r}
cdsrplots::make_volcano(nutlin, 'logFC', 'p_value')
```

### Add labels

Provide `label_var`, a column containing labels for the data points.

* By default `rank_by` = ‘effect’ and `n_labeled` = 10, meaning that the 10 left-/right-most points will be labeled, ranked by effect size
* If `rank_by` = ‘pval’, the `n_labeled` most significant points will be labeled
* Otherwise, user may specify custom points to label with logical vector `label_bool`.

```{r}
cdsrplots::make_volcano(nutlin, 'logFC', 'p_value', label_var = 'gene')
```

```{r}
nutlin %>% dplyr::mutate(top_5_sig = rank(p_value) <= 5) %>% 
  cdsrplots::make_volcano('logFC', 'p_value', label_var = 'gene', 
                          label_bool ='top_5_sig',ggrepel_type = 'label')
```

### Add colors

Provide `color_var`, a categorical column for coloring purposes.

* By default, a grey background/red highlight dual color scheme is used for logical vectors. For all other vector classes, colors are set to categories arbitrarily.
* Otherwise, user may specify custom colors to use with color_values.

```{r}
nutlin %>% dplyr::mutate(fdr = p.adjust(p_value, method = 'fdr')) %>% 
  cdsrplots::make_volcano('logFC', 'p_value', q_var = 'fdr')
```

```{r}
location_colors <- c('left' = '#D95F02', 'right' = '#7570B3', 'bottom' = '#333333')

nutlin %>% 
  dplyr::mutate(location = ifelse(logFC < 0, 'left', 'right')) %>% 
  dplyr::mutate(location = ifelse(p_value > 1e-10, 'bottom', location)) %>% 
  cdsrplots::make_volcano('logFC', 'p_value', color_var = 'location', color_values = location_colors)
```

### Extending functionality with ggplot

Since make_volcano returns a ggplot object, you can make more tweaks using the ggplot syntax.

```{r}
cdsrplots::make_volcano(nutlin, 'logFC', 'p_value') + cdsrplots::theme_publication()
```

```{r}
volcano <- nutlin %>% dplyr::mutate(top_5_sig = rank(p_value) <= 5) %>% 
  cdsrplots::make_volcano('logFC', 'p_value', label_var = 'gene',color_var = 'top_5_sig',
                          label_bool ='top_5_sig',ggrepel_type = 'label')
volcano + aes(size = top_5_sig) + scale_size_manual(values = c(1,3))
```

## Gene set enrichment plots

The `make_gsea_dot` and `make_gsea_bar` functions are a quick and easy way to visualize the results of a gene set enrichment analysis. The functions are designed to work with the [cdsrgsea](https://github.com/broadinstitute/cdsr_gsea) package but they are fexible enough to work with other GSEA packages.

### Example data

As an example we will look for enriched gene sets from the HALLMARK collection using the hypergeometric test.

```{r eval = F}
gene_sets <- cdsrgsea::load_gene_sets()
```

```{r}
nutlin_gsea <- cdsrgsea::run_hyper(nutlin,gene_sets$Hallmark,gene_var = "gene", rank_var = "logFC")
nutlin_gsea %>% head()
```

### Base plot

Make a simple bar plot by providing the data frame returned by `cdsrgsea`.

```{r}
cdsrplots::make_gsea_bar(nutlin_gsea)
```

The default variable names match the variable names returned by `cdsrgsea`.

* `enrich_var` specifies the column containing the enrichment values. By default `enrich_var` = 'odds_ratio' for hypergeometric and 'NES' for GSEA.
* `size_var` specifies the column containing the sizes. By default `size_var` = 'overlap_size' for hypergeometric and 'size' for GSEA.
* `p_var` specifies the column contianing the significance values. By default `p_var` = 'p_value'

Variable names can changed to work with other GSEA packages or to customize the plots. For example we can set`p_var` to 'p_adjust' instead of 'p_value'.

```{r}
cdsrplots::make_gsea_dot(nutlin_gsea,p_var = 'p_adjust')
```

### Single direction

The direction parameter `dir` can be set to 'pos' to only shown positive terms or 'neg' to only show negative terms

```{r}
cdsrplots::make_gsea_dot(nutlin_gsea,dir = "pos")
```

### Change coloring

The `color_by` argument sets how the plot is colored. There are three options

* 'pval' - colors by significance
* 'dir' - colors by the direction of the enrichment
* 'enrich' - colors by enrichment

```{r}
cdsrplots::make_gsea_bar(nutlin_gsea, color_by = "dir")
```

### Change x-axis

The `x_by` argument sets which variable is plotted on the x-axis. There are two options 

* 'pval' - the significance is plotted on the x-axis
* 'enrich' - the enrichment is plotted on the x-axis

```{r}
cdsrplots::make_gsea_bar(nutlin_gsea, color_by = "enrich", x_by = "pval")
```

### Change y-axis

There are a number of parameters that modify the y-axis

* `n_shown` sets the number of terms which are shown.
* `sig_only` determines whether only significant terms are shown.

```{r}
cdsrplots::make_gsea_dot(nutlin_gsea,sig_only = T)
```




Owner

  • Name: Broad Institute
  • Login: broadinstitute
  • Kind: organization
  • Location: Cambridge, MA

Broad Institute of MIT and Harvard

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

DESCRIPTION cran
  • cowplot * imports
  • ggthemes * imports
  • grid * imports
  • scales * imports
  • tidyverse * imports