Color key for d3heatmap in R? - r

is there any way to specify color key for d3heatmap in R? following is the code with which I am able to make the heatmap but could not show a color key. Kindly provide some answers.
library(d3heatmap)
d3heatmap(data, Rowv = TRUE, Colv = TRUE,
distfun = dist, hclustfun = hclust, dendrogram = c("both", "row",
"column", "none"), reorderfun = function(d, w) reorder(d, w), k_row=400, symm = FALSE, scale = "row", na.rm = TRUE,labRow = rownames(data), labCol = colnames(data), digits = 3L,theme = NULL, color = scales::col_quantile("Blues", NULL, 5),
width = 960, height = 500, xaxis_height = 80, yaxis_width = 120,
xaxis_font_size = "12pt", yaxis_font_size = "12pt", brush_color ="#0000FF",
show_grid = TRUE, anim_duration = 0)

Related

How to draw color index in the right side of the heat map graph in R?

How to draw color index in the right side of the graph, something like within a red circle in the attached pic
Used code:
heatmap(df, scale = "row", Rowv = NA, Colv = NA, cexRow = 1.5, cexCol = 1.5,
labRow = c(expression(R^2), "MAPE", "RMSE", "MAE","NSE", "md"))
Full code is:
heatmap(x, Rowv = NULL, Colv = if(symm)"Rowv" else NULL, distfun = dist, hclustfun = hclust, reorderfun = function(d, w) reorder(d, w), add.expr, symm = FALSE, revC = identical(Colv, "Rowv"), scale = c("row", "column", "none"), na.rm = TRUE, margins = c(5, 5), ColSideColors, RowSideColors, cexRow = 0.2 + 1/log10(nr), cexCol = 0.2
+ 1/log10(nc), labRow = NULL, labCol = NULL, main = NULL, xlab = NULL, ylab = NULL, keep.dendro = FALSE, verbose = getOption("verbose"), ...)

Loop in R using paste to plot graphs

Graphics come out blank.
I need to plot several graphs from a GBM analysis, so I am using a loop along with the paste function.
But are all the graphics coming out blank? What can it be? When executing code out of the loop everything works. Thank you
list <- list("A","B", "C")
for (i in list) {
df <- fread(paste("data_", i, ".csv", sep = ""), header = TRUE)
gbm.fit <- gbm( formula = y ~ ., distribution = "gaussian", data = train,n.trees = 1000, interaction.depth = 5, shrinkage = 0.1, cv.folds = 5, n.cores = NULL, verbose = FALSE )
pathname <- paste("gbm", i, ".tiff", sep = "")
tiff( file = pathname, width = 1200, height = 1000, res = 105 )
vip( gbm.fit, num_features = 15, bar = TRUE, width = 0.75, horizontal = TRUE, color = hcl.colors( 15, palette = "Greens2", alpha = NULL, rev = FALSE, fixup = TRUE ), fill = hcl.colors( 15, palette ="Greens", alpha = NULL, rev = TRUE, fixup = TRUE ) )
dev.off()
}
I would like the graphics to come out with the correct content
The vip function uses ggplot2-based graphics. Therefore, either print() the plot or use ggsave() to save the plot to a file:
1. The print() method:
myPlot <- vip( gbm.fit, num_features = 15, bar = TRUE, width = 0.75, horizontal = TRUE,
color = hcl.colors( 15, palette = "Greens2", alpha = NULL, rev = FALSE,
fixup = TRUE ), fill = hcl.colors( 15, palette ="Greens", alpha = NULL,
rev = TRUE, fixup = TRUE ) )
tiff( file = pathname, width = 1200, height = 1000, res = 105 )
print(myPlot)
dev.off()
2. The ggsave() method:
myRes <- 105 # ggsave uses inches, not pixels
ggsave(pathname, myPlot, device = "tiff", width = 1200 / myRes,
height = 1000 / myRes, dpi = myRes)

Pheatmap annotation colors edit size

Pheatmap library(pheatmap) takes annotation_colors to add the header ID colors on the top of each heatmap column.
I want to control and edit the size of the column header (boxes red and blue).
Below is what I have done so far.
library(pheatmap)
set.seed(123)
df<-data.frame( matrix(sample(30), ncol = 5))
colnames(df)<-LETTERS[1:5]
subj<-c("P1", "P2","P3", "T1", "T2","T3")
rownames(df)<-subj
aka2 = data.frame(ID = factor(rep(c("Pat","Trea"), each=3)))
rownames(aka2)<-subj
aka3 = list(ID = c(Pat = "red", Trea="blue"))
pheatmap(t(scale(df)),
annotation_col = aka2,
annotation_colors = aka3[1],
annotation_legend = FALSE,
gaps_col = 3,
show_colnames = T, show_rownames = T, cluster_rows = F,
cluster_cols = F, legend = TRUE,
clustering_distance_rows = "euclidean", border_color = FALSE)

How to adjust column labels in heatmap.3

The following is my code for heatmap.3:
heatmap.3(x = as.matrix(res), dist.FUN = dist2, scale = 'row', color.FUN = col_ylgnbu,
cex.main = 2, trace = 'none', srtCol = 45, adjCol = c(1,0.1),
main = paste(title),
key = T, cexRow = 2, cexCol = 1)
I get the following heatmap using this code:
My question is how can I adjust the column labels so that they don't overlap the heatmap?
Thanks!
You could set adjCol to center justify and offsetCol to move the labels down:
heatmap.3(x = as.matrix(res), dist.FUN = dist2, scale = 'row',
color.FUN = col_ylgnbu,
cex.main = 2, trace = 'none', srtCol = 45,
adjCol = c(1,0), offsetCol=1
main = paste(title),
key = T, cexRow = 2, cexCol = 1)
More notes here: http://earlglynn.github.io/RNotes/package/gplots/heatmap2.html

How do you add borders onto a heatmap created by the pheatmap R package?

I am creating a heatmap using the following code:
pheatmap(tissuedata3,
color = colorRampPalette(rev(c("#D73027", "#FC8D59", "#FEE090", "#FFFFBF", "#E0F3F8", "#91BFDB", "#4575B4")))(100),
cellwidth = 20, cellheight = 2.8,
border=TRUE,
treeheight_row=0,
treeheight_column=0,
kmeans_k = NA,
show_rownames = T, show_colnames = T,
fontsize=2,
scale="none",
clustering_method = "complete",
cluster_rows = FALSE, cluster_cols = TRUE,
clustering_distance_rows = "euclidean",
clustering_distance_cols = "euclidean",
legend=TRUE,
)
However, the resulting heatmap does not contain any borders. Does anyone know how to add borders to the cells and the heatmap as a whole?
I think the correct parameter is border_color whose default is "grey60", so I suspected (incorrectly as it turned out) you were getting partial name match from your argument "border" whose value becomes colors()[1] which is [1] "white".
Try:
library(pheatmap)
pheatmap(tissuedata3,
color = colorRampPalette(rev(c("#D73027", "#FC8D59", "#FEE090", "#FFFFBF", "#E0F3F8", "#91BFDB", "#4575B4")))(100),
cellwidth = 20, cellheight = 3, # changed to 3
border_color="blue",
treeheight_row=0,
treeheight_column=0,
kmeans_k = NA,
show_rownames = T, show_colnames = T,
fontsize=2,
scale="none",
clustering_method = "complete",
cluster_rows = FALSE, cluster_cols = TRUE,
clustering_distance_rows = "euclidean",
clustering_distance_cols = "euclidean",
legend=TRUE
)

Resources