Anyone know how to make a heatmap?

This forum made possible through the generous support of SDN members, donors, and sponsors. Thank you.
Are you familiar with R and ggplot? You could make a dataframe with the point A and B averages in the first two columns, and the degree you see that combination as the 3rd. Then plot column 1 vs 2 and use geom_tile to color the combination with the values in column 3. I am on mobile but can link sample code later if you'd like
 
Are you familiar with R and ggplot? You could make a dataframe with the point A and B averages in the first two columns, and the degree you see that combination as the 3rd. Then plot column 1 vs 2 and use geom_tile to color the combination with the values in column 3. I am on mobile but can link sample code later if you'd like

I second this approach - R is pretty good at visualization.

Alternatively, if you're more used to Python, using Python with Matplotlib could create a heatmap much like what you want (Plotting a 2D heatmap with Matplotlib), and it might be easier to figure out (dataframes in R aren't always intuitive). You could also try Seaborn, which has a builtin heatmap generator (seaborn.heatmap — seaborn 0.9.0 documentation).

Matlab has the ability to do something similar if you come from an engineering background where you learned that language (Create heatmap chart - MATLAB heatmap).

I haven't tried the website above, but it looks like a pretty good alternative if you really don't want to code anything yourself for this purpose (which is understandable).

For the heatmaps in all the scenarios, your "distance from A" could be the x-axis, and your "distance from B" could be the y-axis for the data, and the color/intensity of each datapoint could be the "degree of the artery".
 
Are you familiar with R and ggplot? You could make a dataframe with the point A and B averages in the first two columns, and the degree you see that combination as the 3rd. Then plot column 1 vs 2 and use geom_tile to color the combination with the values in column 3. I am on mobile but can link sample code later if you'd like

That would be awesome. Thank you so much
 
That would be awesome. Thank you so much

In the example below I compared the number of T cell clonotypes that are shared between 4 conditions (T cells from patients with/without cytomegalovirus exposure, and +/- in vitro stimulation of those T cells with CRV, a CMV-derived epitope). This code is from my first problem set in my first computer science class ever, so there are probably more efficient ways of going about this...

# Below I create dataframes containing the number of shared clonotypes between each possible combination of the datasets e.g. ps_pu is the overlap between ps and pu
# ps = CMV positive CRV stimulated
# pu = CMV positive CRV unstimulated
# ns = CMV negative CRV stimulated
# nu = CMV nevative CRV unstimulated

ps_pu = inner_join(pstim, punstim,by=c('CDR3.sequence','V.gene','J.gene'),suffix=c('.ps','.pu'))

ps_ns = inner_join(pstim, nstim,by=c('CDR3.sequence','V.gene','J.gene'),suffix=c('.ps','.ns'))

ps_nu = inner_join(pstim, nunstim,by=c('CDR3.sequence','V.gene','J.gene'),suffix=c('.ps','.nu'))

pu_ns = inner_join(punstim, nstim,by=c('CDR3.sequence','V.gene','J.gene'),suffix=c('.pu','.ns'))

pu_nu = inner_join(punstim, nunstim,by=c('CDR3.sequence','V.gene','J.gene'),suffix=c('.pu','.nu'))

ns_nu = inner_join(nstim, nunstim,by=c('CDR3.sequence','V.gene','J.gene'),suffix=c('.ns','nu'))

# Creating a data frame containing the number of overlapping clonotypes for each unique combination of samples
heatmap = data.frame(
samp1 = c('+ Stim','+ Stim','+ Stim','+ Unstim','+ Unstim','- Stim'),
samp2 = c('+ Unstim','- Stim','- Unstim','- Stim','- Unstim','- Unstim'),
overlap=c(nrow(ps_pu),nrow(ps_ns),nrow(ps_nu),nrow(pu_ns),nrow(pu_nu),nrow(ns_nu))
)

# Plotting the heatmap
ggplot(heatmap, aes(x = samp1, y=samp2)) +
geom_tile(aes(fill = overlap)) +
scale_fill_gradient(low = "white", high = "red", name = "Number of Overlapping Clonotypes") +
theme_classic() +
labs(x = "", y = "") +
ggtitle("Clonotype Overlap Between TCR Repertoires") +
geom_text(aes(fill = overlap, label = overlap))

267840
 

I just wanted to point out that the most relevant part of the code is as below. The reason I do this is just to make it clearer what OP might want to focus on if they wanted to reuse this code or replicate it.

# Plotting the heatmap ggplot(heatmap, aes(x = samp1, y=samp2)) + geom_tile(aes(fill = overlap)) + scale_fill_gradient(low = "white", high = "red", name = "Number of Overlapping Clonotypes") + theme_classic() + labs(x = "", y = "") + ggtitle("Clonotype Overlap Between TCR Repertoires") + geom_text(aes(fill = overlap, label = overlap))

The rest of the code is primarily setting up the dataframe which contains the variables samp1, samp2, and overlap. You'd obviously need to change the name of the legend (colorbar), the title, some properties (like color and theme) and the X and Y values (which are set up in the dataframe declaration below).

# Creating a data frame containing the number of overlapping clonotypes for each unique combination of samples heatmap = data.frame( samp1 = c('+ Stim','+ Stim','+ Stim','+ Unstim','+ Unstim','- Stim'), samp2 = c('+ Unstim','- Stim','- Unstim','- Stim','- Unstim','- Unstim'), overlap=c(nrow(ps_pu),nrow(ps_ns),nrow(ps_nu),nrow(pu_ns),nrow(pu_nu),nrow(ns_nu)) )

Good luck OP, if you need more help, feel free to ask. If you're completely unsure on what to do with this code, just ask (or PM me) and I might be able to send you some code (albeit in a different language since R isn't my forte).
 
Same question but does anyone know how to make a circular heatmap? (I have zero coding experience, is there a superfast way to teach myself enough to know how to use R?)
 
Same question but does anyone know how to make a circular heatmap? (I have zero coding experience, is there a superfast way to teach myself enough to know how to use R?)

Circular heatmaps are a bit more complicated, but doable in the same sense depending on the structure of your data. I haven't personally made a circular heatmap, but it seems that there's multiple options in R, MATLAB, and Python.

In R, there's a circular package that includes a function to make a heatmap using polar coordinates: heatmap.circular function | R Documentation

In Python, it seems Matplotlib supports this natively by using polar projections for the axes (Circular interpolated heat map plot using python).

In MATLAB, it's a bit more complicated than in R or Python, but you can use the pcolor function (Pseudocolor plot - MATLAB pcolor), which someone modified to use Polar coordinates here: (pcolor in polar coordinates - File Exchange - MATLAB Central)

I don't think there's necessarily a "superfast" way to teach yourself to use R unless you know at least one programming language (my philosophy is that learning a new language for basic use is just learning new syntax if you already know at least one).

It may be more worthwhile to commission the code from someone else or to find someone who is willing to help with this, unless you're interested in learning R for other purposes as well (it's quite powerful as a data analysis toolbox). If you're willing to invest more time beyond just using it for the heatmap, you could try this website (Learn R | Codecademy) to learn the basics of coding and how to use dataframes in R (though I haven't personally used this course).
 
Wow, you guys are lightyears ahead of me in terms of this kinda stuff haha. I have zero background in coding/engineering and this stuff is all new to me. I was really hoping there was something where I can just plug in the numbers and it would create something for me, haha.

@Seihai can i send you a PM?
 
Wow, you guys are lightyears ahead of me in terms of this kinda stuff haha. I have zero background in coding/engineering and this stuff is all new to me. I was really hoping there was something where I can just plug in the numbers and it would create something for me, haha.

@Seihai can i send you a PM?

@SynapticDoctah Feel free to send me a PM!
 
Top