All Projects → stemangiola → Tidyheatmap

stemangiola / Tidyheatmap

Licence: gpl-3.0
Draw heatmap simply using a tidy data frame

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Tidyheatmap

Moderndive book
Statistical Inference via Data Science: A ModernDive into R and the Tidyverse
Stars: ✭ 527 (+249.01%)
Mutual labels:  tidyverse, dplyr, rstudio
parcours-r
Valise pédagogique pour la formation à R
Stars: ✭ 25 (-83.44%)
Mutual labels:  dplyr, tidyverse
casewhen
Create reusable dplyr::case_when() functions
Stars: ✭ 64 (-57.62%)
Mutual labels:  dplyr, tidyverse
Tidy
Tidy up your data with JavaScript, inspired by dplyr and the tidyverse
Stars: ✭ 307 (+103.31%)
Mutual labels:  tidyverse, dplyr
Tidyquery
Query R data frames with SQL
Stars: ✭ 138 (-8.61%)
Mutual labels:  tidyverse, dplyr
advanced-data-wrangling-in-R-legacy
Advanced-data-wrangling-in-R, Workshop
Stars: ✭ 14 (-90.73%)
Mutual labels:  dplyr, tidyverse
rfordatasciencewiki
Resources for the R4DS Online Learning Community, including answer keys to the text
Stars: ✭ 40 (-73.51%)
Mutual labels:  rstudio, tidyverse
bioc 2020 tidytranscriptomics
Workshop on tidytranscriptomics: Performing tidy transcriptomics analyses with tidybulk, tidyverse and tidyheatmap
Stars: ✭ 25 (-83.44%)
Mutual labels:  heatmap, tidyverse
Tidyquant
Bringing financial analysis to the tidyverse
Stars: ✭ 635 (+320.53%)
Mutual labels:  tidyverse, dplyr
Tidylog
Tidylog provides feedback about dplyr and tidyr operations. It provides wrapper functions for the most common functions, such as filter, mutate, select, and group_by, and provides detailed output for joins.
Stars: ✭ 428 (+183.44%)
Mutual labels:  tidyverse, dplyr
datar
A Grammar of Data Manipulation in python
Stars: ✭ 142 (-5.96%)
Mutual labels:  dplyr, tidyverse
Big Data
🔧 Use dplyr to analyze Big Data 🐘
Stars: ✭ 93 (-38.41%)
Mutual labels:  dplyr, rstudio
implyr
SQL backend to dplyr for Impala
Stars: ✭ 74 (-50.99%)
Mutual labels:  dplyr, tidyverse
tidyweek
Repo dedicated to #tidyweek & Mentorship pilot
Stars: ✭ 25 (-83.44%)
Mutual labels:  rstudio, tidyverse
CSSS508
CSSS508: Introduction to R for Social Scientists
Stars: ✭ 28 (-81.46%)
Mutual labels:  dplyr, tidyverse
learning R
List of resources for learning R
Stars: ✭ 32 (-78.81%)
Mutual labels:  dplyr, rstudio
R-advantages-over-python
This repository enumerates all the reasons why R is better than python for DS
Stars: ✭ 59 (-60.93%)
Mutual labels:  dplyr, rstudio
eeguana
A package for manipulating EEG data in R.
Stars: ✭ 16 (-89.4%)
Mutual labels:  dplyr, tidyverse
Timetk
A toolkit for working with time series in R
Stars: ✭ 371 (+145.7%)
Mutual labels:  tidyverse, dplyr
Nanny
A tidyverse suite for (pre-) machine-learning: cluster, PCA, permute, impute, rotate, redundancy, triangular, smart-subset, abundant and variable features.
Stars: ✭ 17 (-88.74%)
Mutual labels:  tidyverse, rstudio

tidyHeatmap

Lifecycle:maturing DOI

Please have a look also to

  • nanny for tidy high-level data analysis and manipulation
  • tidygate for adding custom gate information to your tibble
  • tidySCE for tidy manipulation of Seurat objects
  • tidyseurat for tidy manipulation of Seurat objects
  • tidybulk for tidy high-level data analysis and manipulation
  • tidySE for heatmaps produced with tidy principles

website: stemangiola.github.io/tidyHeatmap/

tidyHeatmap is a package that introduces tidy principles to the creation of information-rich heatmaps. This package uses ComplexHeatmap as graphical engine.

Advantages:

  • Modular annotation with just specifying column names
  • Custom grouping of rows is easy to specify providing a grouped tbl. For example df %>% group_by(...)
  • Labels size adjusted by row and column total number
  • Default use of Brewer and Viridis palettes

Functions/utilities available

Function Description
heatmap Plot base heatmap
add_tile Add tile annotation to the heatmap
add_point Add point annotation to the heatmap
add_bar Add bar annotation to the heatmap
add_line Add line annotation to the heatmap
layer_symbol Add layer of symbols on top of the heatmap
save_pdf Save the PDF of the heatmap

Installation

To install the most up-to-date version

devtools::install_github("stemangiola/tidyHeatmap")

To install the most stable version (however please keep in mind that this package is under a maturing lifecycle stage)

install.packages("tidyHeatmap")

Contribution

If you want to contribute to the software, report issues or problems with the software or seek support please open an issue here

Input data frame

The heatmaps visualise a multi-element, multi-feature dataset, annotated with independent variables. Each observation is a element-feature pair (e.g., person-physical characteristics).

element feature value independent_variables
chr or fctr chr or fctr numeric

Let’s transform the mtcars dataset into a tidy “element-feature-independent variables” data frame. Where the independent variables in this case are ‘hp’ and ‘vs’.

mtcars_tidy <- 
    mtcars %>% 
    as_tibble(rownames="Car name") %>% 
    
    # Scale
    mutate_at(vars(-`Car name`, -hp, -vs), scale) %>%
    
    # tidyfy
    pivot_longer(cols = -c(`Car name`, hp, vs), names_to = "Property", values_to = "Value")

mtcars_tidy
## # A tibble: 288 x 5
##    `Car name`       hp    vs Property Value[,1]
##    <chr>         <dbl> <dbl> <chr>        <dbl>
##  1 Mazda RX4       110     0 mpg          0.151
##  2 Mazda RX4       110     0 cyl         -0.105
##  3 Mazda RX4       110     0 disp        -0.571
##  4 Mazda RX4       110     0 drat         0.568
##  5 Mazda RX4       110     0 wt          -0.610
##  6 Mazda RX4       110     0 qsec        -0.777
##  7 Mazda RX4       110     0 am           1.19 
##  8 Mazda RX4       110     0 gear         0.424
##  9 Mazda RX4       110     0 carb         0.735
## 10 Mazda RX4 Wag   110     0 mpg          0.151
## # … with 278 more rows

Plot

For plotting, you simply pipe the input data frame into heatmap, specifying:

  • The rows, cols relative column names (mandatory)
  • The value column name (mandatory)
  • The annotations column name(s)

mtcars

mtcars_heatmap <- 
    mtcars_tidy %>% 
        heatmap(`Car name`, Property, Value ) %>%
        add_tile(hp)

mtcars_heatmap

Save

mtcars_heatmap %>% save_pdf("mtcars_heatmap.pdf")

Grouping

We can easily group the data (one group per dimension maximum, at the moment only the vertical dimension is supported) with dplyr, and the heatmap will be grouped accordingly

mtcars_tidy %>% 
    group_by(vs) %>%
    heatmap(`Car name`, Property, Value ) %>%
    add_tile(hp)

Custom palettes

We can easily use custom palette, using strings, hexadecimal color character vector,

mtcars_tidy %>% 
    heatmap(
        `Car name`, 
        Property, 
        Value,
        palette_value = c("red", "white", "blue")
    )

Or a grid::colorRamp2 function for higher flexibility

mtcars_tidy %>% 
    heatmap(
        `Car name`, 
        Property, 
        Value,
        palette_value = circlize::colorRamp2(c(-2, -1, 0, 1, 2), viridis::magma(5))
    )

Multiple groupings and annotations

tidyHeatmap::pasilla %>%
    group_by(location, type) %>%
    heatmap(
            .column = sample,
            .row = symbol,
            .value = `count normalised adjusted`
        ) %>%
    add_tile(condition) %>%
    add_tile(activation)

Annotation types

This feature requires >= 0.99.20 version

“tile” (default), “point”, “bar” and “line” are available

# Create some more data points
pasilla_plus <- 
    tidyHeatmap::pasilla %>%
        dplyr::mutate(act = activation) %>% 
        tidyr::nest(data = -sample) %>%
        dplyr::mutate(size = rnorm(n(), 4,0.5)) %>%
        dplyr::mutate(age = runif(n(), 50, 200)) %>%
        tidyr::unnest(data) 

# Plot
pasilla_plus %>%
        heatmap(
            .column = sample,
            .row = symbol,
            .value = `count normalised adjusted`
        ) %>%
    add_tile(condition) %>%
    add_point(activation) %>%
    add_tile(act) %>%
    add_bar(size) %>%
    add_line(age)

Layer symbol

Add a layer on top of the heatmap

tidyHeatmap::pasilla %>%
    
    # filter
    filter(symbol %in% head(unique(tidyHeatmap::pasilla$symbol), n = 10)) %>%
    
    heatmap(
            .column = sample,
            .row = symbol,
            .value = `count normalised adjusted`
        ) %>% 
    layer_symbol(
        `count normalised adjusted log` > 6 & sample == "untreated3" 
    )

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].