Learn R Programming

⚠️There's a newer version (1.11.6) of this package.Take me there.

tidyHeatmap

(If you like tidyverse and RNA, try tidybulk for tidy and modular transcriptomics analyses!)

Tidy heatmap. This package is a tidy wrapper of the package ComplexHeatmap. The goal of this package is to interface tidy data frames with this powerful tool.

Some of the advantages are:

  • Row and/or columns colour annotations are easy to integrate just specifying one parameter (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

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")

Input data frame

mtcars_tidy = 
    mtcars %>% 
    as_tibble(rownames="Car name") %>% 
    
    # Scale
    mutate_at(vars(-`Car name`, -hp, -vs), scale) %>%
    
    # tidyfy
    gather(Property, Value, -`Car name`, -hp, -vs)

mtcars_tidy
## # A tibble: 288 x 5
##    `Car name`           hp    vs Property  Value
##    <chr>             <dbl> <dbl> <chr>     <dbl>
##  1 Mazda RX4           110     0 mpg       0.151
##  2 Mazda RX4 Wag       110     0 mpg       0.151
##  3 Datsun 710           93     1 mpg       0.450
##  4 Hornet 4 Drive      110     1 mpg       0.217
##  5 Hornet Sportabout   175     0 mpg      -0.231
##  6 Valiant             105     1 mpg      -0.330
##  7 Duster 360          245     0 mpg      -0.961
##  8 Merc 240D            62     1 mpg       0.715
##  9 Merc 230             95     1 mpg       0.450
## 10 Merc 280            123     1 mpg      -0.148
## # … 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,
            annotation = 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,
        annotation = 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`,
            annotation = c(condition, 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`,
            annotation = c(condition, activation, act, size, age),
            type = c("tile", "point", "tile", "bar", "line")
        )

Copy Link

Version

Install

install.packages('tidyHeatmap')

Monthly Downloads

1,611

Version

1.0.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Stefano Mangiola

Last Published

June 23rd, 2020

Functions in tidyHeatmap (1.0.1)

get_abundance_norm_if_exists

Get column names either from user or from attributes
get_x_y_annotation_columns

get_x_y_annotation_columns
get_sample_transcript_counts

Get column names either from user or from attributes
ifelse_pipe

This is a generalisation of ifelse that acceots an object and return an objects
parse_formula

.formula parser
get_sample_transcript

Get column names either from user or from attributes
get_sample_counts

Get column names either from user or from attributes
heatmap.default

Creates a `ComplexHeatmap` plot from `tbl_df`
prepend

From rlang deprecated
heatmap

Creates a `ComplexHeatmap` plot from `tbl_df`
save_pdf,Heatmap-method

save_pdf
quo_names

Convert array of quosure (e.g. c(col_a, col_b)) into character vector
save_pdf

Save plot on PDF file
check_if_counts_is_na

Check whether there are NA counts
scale_design

Scale design matrix
pasilla

Example data set Pasilla
get_elements_features

Get column names either from user or from attributes
plot_heatmap

plot_heatmap
get_elements

Get column names either from user or from attributes
get_elements_features_abundance

Get column names either from user or from attributes
scale_robust

Scale counts in a robust way against sd == 0
heatmap.tbl_df

Creates a `ComplexHeatmap` plot from `tbl_df`
ifelse2_pipe

This is a generalisation of ifelse that acceots an object and return an objects
select_closest_pairs

Sub function of remove_redundancy_elements_though_reduced_dimensions
type_to_annot_function

type_to_annot_function annot_*
as_matrix

Get matrix from tibble
N52

Example data set N52
add_class

Add class to abject
check_if_duplicated_genes

Check whether there are duplicated genes/transcripts
add_attr

Add attribute to abject
annot_to_list

annot_to_list
check_if_wrong_input

Check whether there are NA counts
drop_class

Remove class to abject
error_if_log_transformed

Check whether a numeric vector has been log transformed