Learn R Programming

heatmaply (version 0.5.0)

heatmaply: Creates a plotly heatmap

Description

An object of class heatmapr includes all the needed information for producing a heatmap. The goal is to seperate the pre-processing of the heatmap elements from the graphical rendaring of the object, which could be done

Usage

heatmaply(x, colors = viridis(n = 256, alpha = 1, begin = 0, end = 1, option = "viridis"), limits = NULL, na.value = "grey50", row_text_angle = 0, column_text_angle = 45, margin = 0, row_dend_left = FALSE, ..., scale_fill_gradient_fun = scale_fill_gradientn(colors = if (is.function(colors)) colors(256) else colors, na.value = na.value, limits = limits), grid_color = NA, srtRow, srtCol, xlab = "", ylab = "", titleX = TRUE, titleY = TRUE, hide_colorbar = FALSE, key.title = NULL, return_ppxpy = FALSE)

Arguments

x
can either be a heatmapr object, or a numeric matrix Defaults to TRUE unless x contains any NAs.
colors
a vector of colors to use for heatmap color. The default uses viridis(n=256, alpha = 1, begin = 0, end = 1, option = "viridis") It is passed to scale_fill_gradientn. If colors is a color function (with the first argument being `n` = the number of colors), it will be used to create 256 colors from that function.
limits
a two dimensional numeric vector specifying the data range for the scale.
na.value
color to use for missing values (default is "grey50").
row_text_angle
numeric (Default is 0), the angle of the text of the rows. (this is called srtRow in heatmap.2)
column_text_angle
numeric (Default is 45), the angle of the text of the columns. (this is called srtCol in heatmap.2)
margin
passed to subplot. Default is 0. Either a single value or four values (all between 0 and 1). If four values are provided, the first is used as the left margin, the second is used as the right margin, the third is used as the top margin, and the fourth is used as the bottom margin. If a single value is provided, it will be used as all four margins.
row_dend_left
logical (default is FALSE). Should the row dendrogram be plotted on the left side of the heatmap. If false then it will be plotted on the right side.
...
other parameters passed to heatmapr (currently, various parameters may be ignored.
scale_fill_gradient_fun
A function that creates a smooth gradient for the heatmap. The default uses scale_fill_gradientn with the values of colors, limits, and na.value that are supplied by the user. The user can input a customized function, such as scale_colour_gradient() in order to get other results (although the virids default is quite recommended)
grid_color
control the color of the heatmap grid. Default is NA. Value passed to geom_tile. This parameter is currently not working until this is added in plotly.
srtRow
if supplied, this overrides row_text_angle (this is to stay compatible with heatmap.2)
srtCol
if supplied, this overrides column_text_angle (this is to stay compatible with heatmap.2)
xlab
A character title for the x axis.
ylab
A character title for the y axis.
titleX
logical (TRUE). should x-axis titles be retained? (passed to subplot).
titleY
logical (TRUE). should y-axis titles be retained? (passed to subplot).
hide_colorbar
logical (FALSE). If TRUE, then the color bar is hidden.
key.title
(character) main title of the color key. If set to NULL (default) no title will be plotted.
return_ppxpy
logical (FALSE). If TRUE, then no plotting is done and the p, px and py objects are returned (before turning into plotly objects). This is a temporary option which might be removed in the future just to make it easy to create a ggplot heatmaps.

Please submit an issue on github if you have a feature that you wish to have added)

Examples

Run this code
## Not run: 
# 
# # mtcars
# # x <- heatmapr(mtcars)
# library(heatmaply)
# heatmaply(iris[,-5], k_row = 3, k_col = 2)
# heatmaply(cor(iris[,-5]))
# heatmaply(cor(iris[,-5]), limits = c(-1,1))
# heatmaply(mtcars, k_row = 3, k_col = 2)
# 
# # make sure there is enough room for the labels:
# heatmaply(mtcars) %>% layout(margin = list(l = 130, b = 40))
# 
# # control text angle
# heatmaply(mtcars, column_text_angle = 90) %>% layout(margin = list(l = 130, b = 40))
# # the same as using srtCol:
# # heatmaply(mtcars, srtCol = 90) %>% layout(margin = list(l = 130, b = 40))
# 
# 
# 
# x <- mtcars
# # different colors
# heatmaply(x, colors = heat.colors(200))
# # using special scale_fill_gradient_fun colors
# heatmaply(x, scale_fill_gradient_fun = scale_colour_gradient())
# 
# 
# # We can join two heatmaps together:
# library(heatmaply)
# hm1 <- heatmaply(mtcars) %>% layout(margin = list(l = 130, b = 40))
# hm2 <- heatmaply(mtcars, scale = "col") %>% layout(margin = list(l = 130, b = 40))
# subplot(hm1, hm2, margin = .2)
# 
# # If we want to share the Y axis, then it is risky to keep any of the dendrograms:
# library(heatmaply)
# hm1 <- heatmaply(mtcars, Colv = FALSE, Rowv = FALSE) %>%
#    layout(margin = list(l = 130, b = 40))
# hm2 <- heatmaply(mtcars, scale = "col" , Colv = FALSE, Rowv = FALSE) %>%
#    layout(margin = list(l = 130, b = 40))
# subplot(hm1, hm2, margin = .02, shareY = TRUE)
# 
# # We can save heatmaply as a widget by using:
# library(heatmaply)
# library(htmlwidgets)
# heatmaply(iris[,-5]) %>%
#    saveWidget(file="test.html",selfcontained = FALSE)
# 
# 
# 
# ## End(Not run)

Run the code above in your browser using DataLab