Heatmap generation - r

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.

Related

Overlapping Field Names in mice::md.pattern

Generating a graphic in R using the mice package using the md.pattern function to graph the rows and columns of a data.frame where there are missing data values. This function creates a plot pasted below. The field headers are overlapping and are illegible. I've tried expanding the parameters of the image but that doesn't change anything.
Any ideas on how I can work around this? Any insight is appreciated.
you can try this
md.pattern(x, plot = TRUE, rotate.names = TRUE)

Plotting discontinuous line segments in Python

Firstly, I am very, very new to Python. I am trying to come close to a product I make in Excel charts by plotting X and Y. I want to be able to export the data from Excel to a text file and the read into Python to produce the chart. In Excel I have the line segments, defined by X and Y values, separated by empty cells in columns and the other segments in other columns. For right now I am just exporting a single column with the objective of having more columns. So if the image shows up in this post you will see that the different line segments are all connected by straight lines, sort of like Etch-a-Sketch. I got errors when I had blank lines in the text file where I had empty cells in the Excel data. Any guidance would be greatly appreciated.
Attempted chart

Cufflinks: how to subplot heatmaps w/ Cufflinks in Jupyter/ipython Notebook?

I have read the Cufflinks examples. The only subplots examples are generated from a single DataFrame with a subplots=True parameter and an optional shape parameter (i.e. df.iplot(..., subplots=True, shape=(...), ...). As I understand it, the mechanism is that when subplots=True is provided, each column of the DataFrame is plotted as a subplot.
Now, about heatmaps in Cufflinks. The example in the same link shows that the DataFrame of a heatmap of N * M is simply an N * M DataFrame where the column names and indexes tells the x and y coordiates and the values are the "heat" of each cell of the grid.
Combining the two, it seems that if I have two heatmaps (thus two DataFrames), I cannot plot both in a subplot-fashion, because subplots require a single DataFrame and I cannot combine two heatmap DataFrames into one.
Anyone has any idea how it might work?
BTW, I also tried plotly.offline.iplot(..., subplots=True, ...) and the parameter is not supported.
EDIT
There is another question (from me, too) asking about doing the same in plotly, which got answered. So if you are working w/ plotly directly then that's the answer you might want to take a look.
This question is about using Cufflinks to achieve the same. It still seems impossible (or at least very difficult) to me.
You can use the following:
import cufflinks as cf
df1=cf.datagen.heatmap()
df2=cf.datagen.heatmap()
cf.subplots([df1.figure(kind='heatmap'),df2.figure(kind='heatmap')]).iplot()
You can do this with as many heatmaps, and you can also use the shape parameters.

Plots of different rows on the same graph

I found an interesting thread about plotting but I'm not happy with the answer. I would like to plot different amount of rows on the same graph. Just giving me the possibility to add as much rows as I want to.
I'd like to use glopts library but I am open for any other. First of all I want to plot those rows into pdf file. The script which I want to modify is:
which_rows <- c(12,156,4432) ## I want to choose which row I want to plot
pdf(file='Plots'.pdf)
x <- 1:(ncol(data_plot)-1) ## Can it be changed to use the name of the columns instead of pure numbers ?
for(i in which_rows){
## create new pdf page BUT I WANT TO PLOT IT ON THE SAME GRAPH!
plot(x=x,y=data_plot[i,-1],type='b',main=data_plot[i,1],xlab='columns',ylab='Intensity')
}
# closing pdf
dev.off()
Can you help me to modify this script to print just all of the rows which I decide on the same graph ? Would be great if you show me how I can jsut add new page in this pdf file using the other set of rows like which_rows2.
Of course each plot should has diffent colour or something.
Edit:
use points()to add points to the existing plot

Creating a sidebar with heatmap.2

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.

Resources