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:
df %>% group_by(...)
To install the most up-to-date version
To install the most stable version (however please keep in mind that this package is under a maturing lifecycle stage)
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
For plotting, you simply pipe the input data frame into heatmap, specifying:
mtcars
mtcars_heatmap =
mtcars_tidy %>%
heatmap(
`Car name`,
Property,
Value,
annotation = hp
)
mtcars_heatmap
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
We can easily use custom palette, using strings, hexadecimal color character vector,
Or a grid::colorRamp2 functionfor higher flexibility
mtcars_tidy %>%
heatmap(
`Car name`,
Property,
Value,
palette_value = circlize::colorRamp2(c(-2, -1, 0, 1, 2), viridis::magma(5))
)
tidyHeatmap::pasilla %>%
group_by(location, type) %>%
heatmap(
.column = sample,
.row = symbol,
.value = `count normalised adjusted`,
annotation = c(condition, activation)
)
“tile” (default), “point”, “bar” and “line” are available
# Chreate 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 %>%
tidyHeatmap::heatmap(
.column = sample,
.row = symbol,
.value = `count normalised adjusted`,
annotation = c(condition, activation, act, size, age),
type = c("tile", "point", "tile", "bar", "line")
)