Creating a sidebar with heatmap.2 - r

I have a file with genomic data for which I am trying to create a heatmap of the data together with a sidebar for the chromosome information. To make the heatmap I converted the numerical values from my file to create a a data matrix that I was then able to plot:
Heatmap <- heatmap.2(DataMatrix, trace="none", col=greenred, key=T, keysize=1.5, labRow=NA, density.info="none", Colv=FALSE)
However, I would like to add an additional color side bar to indicate the chromosome location of the said data. In particular I would like to have just two colors, say "black" if it's from "chrX" or "yellow" from any other chromosome. The column with this information is not in my data matrix and I'm not sure how to include this info into my heatmap. Any help would be greatly appreciated!

The heatmap.2 function has a RowSideColors argument for this purpose, as you might infer from the documentation:
RowSideColors: (optional) character vector of length 'nrow(x)'
containing the color names for a vertical side bar that may
be used to annotate the rows of 'x'.
I've also recently discovered the aheatmap function in the NMF package, which makes nice heatmaps with an arbitrary number of annotation rows/columns on your heatmap. Included on that homepage you'll find several links to heatmap examples.

Related

Using a Pre-Made Dendrogram to Order Samples in Heatmap3 in R

I'm trying to use heatmap3 to visualize my bacterial community data. I have already clustered my samples, and have a dendrogram from hclust that I want to use to order my samples in the heatmap, while showing the dendrogram as well. However, the data file that I am putting into heatmap3 has been collapsed to the genera level, so the structure that I had before isn't immediately apparent to heatmap3, and I therefore don't want heatmap3 to try to do its own clustering.
I've tried using my hclust object as a dendrogram and passing it to Colv, but the order of the samples in my heatmap, for whatever reason, becomes literally random while the dendrogram looks correct. When I extract the order of samples in my dendrogram and re-order my input matrix according to this order (without a dendrogram), I get visible clustering. Essentially what I want is to give heatmap my dendrogram that I made from an hclust function, and have it order the samples in that order WITH the dendrogram above, and then plot the relative abundances in the heatmap. What am I missing?
Unfortunately I don't have data that I'm able to provide, or an illustrative example. If this question is impossible to answer without data and R code, I will do my best to put something together.
You can try pheatmap package there parameters cluster_rows and cluster_cols accept hclust objects.

R: How to automatically set the color of different groups in survival plot

I am plotting the survival probability for my dataframe with 8 different groups with this command:
fit2<-Surv((time=t2$uptimeDay,event=t2$solved,type='right')~t2$cluster)
plot(fit2,conf.int=F,xlim=c(0, 250),mark.time=c(1,50,100,200),mark=c(1,3,4,2,5,7,6,8,9,10),lwd=1,cex=0.7,lty = 1:11,xlab='Time(days)',ylab='Survival Probability')
the cluster here is a number between 1 and 10.
I would like to know how to automatically set the colors of the curves together with an automatic legend using key of the curves.
Can somebody help me out with this?
I have a function that I use for Kaplan-Meier curves that is based on ggplot2, which will take care of the colors and legends for you. Regrettably, I've not gotten around to packaging it up in any sensible way. But you can download the source code from
https://gist.github.com/nutterb/004ade595ec6932a0c29
And some examples on how to use it from
https://gist.github.com/nutterb/fb19644cc18c4e64d12a
It's not clear what you mean by making this "automatic" and the desire to "use the key of the curves", but perhaps you are asking that the colors of the curves match the legend.
png()
mycols=c("red","blue")
plot(prio.fit, fill=mycols)
legend(x="bottomleft", col=mycols, legend=mycols)
dev.off()
If you want this mated to a dataset and wanted to specify particular colors for your groups, then you will need to provide a dataset so there is something meaningful to use as labels, and be more specific about the coloring schema needed.

plot igraph in a big area

Just wondering if it is possible to increase the size of the plot so that the nodes and edges can be more scattered over the plot.
Original plot:
What are expected:
I tried many parameters in the layout function such as area, niter, and so on, but all of them do not work. By the way, I am using 'igraph' package in R.
If you are referring to the actual size of the produced output (pdf, png, etc), you can configure it with the width and height parameters. Check this link for png,bpm, etc, and this link for PDF format.
A MWE is something like this:
png("mygraph.png", heigh=400, width=600)
#functions to plot your graph
dev.off()
If you are referring to the size of the graphic produced by the layout function, as #MrFlick referred, you should check the parameters of the particular layout you are using.
Hope it helps you.
In your second graph, it's obviously the graph can be divided into several clusters (or sections). If I understood you correctly, you want to have a layout that separates your clusters more visibly.
Then you can draw this by calculating a two-level layout:
First, calculate the layout of the graph in order to find a place for each cluster.
Second, calculate the layout in each cluster according to first step and plot nodes in the corresponding place.

R confusion heatmap

I have created my first confusion heatmap using the code I found here.
As I result I got a very nice plot with an "increasing" diagonal showing that the predicted and actual data are closely related.
Now, when I look up other confusion matrices, all of them show a "decreasing" diagonal and I'm wondering whether I should adapt my plot in that way (and if so: how?).
Any ideas on that?
By default, R displays a heatmap with the row names ordered from bottom to top, rather than top to bottom.
Here's how to change the ordering

Heatmap generation

I have an Excel file with two different columns. One column have values ranging from 2 to 15 and other column have values ranging from positive to negative numbers.
I want to produce a heatmap in such a way that for first column each value should have a different color. Second column should be in the form of a gradient.
I tried using excel conditional formatting to do this.
But I want to know is there any way to do it in R?
The R command image() takes a matrix and makes a heat-map from it. see the help page: ?image. Also worth considering is the heatmap function, which is basically image() with some clustering applied. Below are two examples from these two plotting routines:
image(volcano,col = terrain.colors(30))
heatmap(volcano,col = terrain.colors(30))
Probably the easiest way to export your data from Excel to R is to save it as a .csv file (comma or tab-separated text file), and then import it using read.table()
You can easily create an interactive heatmap in R using plotly:
library(plotly)
plot_ly(z = volcano, type = "heatmap")
More instructions here.

Resources