-1

I'm trying to create a heatmap to display mutation distribution for my data using R.

Here's a snapshot of my data

TCGA_ID         Gene_Name   Effect
TCGA-A5-A0VP    FCGR2A      splice_donor_variant
TCGA-BG-A18B    FCGR2A      splice_donor_variant
TCGA-A5-A0VO    FCGR2A      stop_gained

I want to plot a heatmap at which x-axis is "TCGA_ID" and Y-axis is "Gene_name" and using "Effect" as a filling.

I use this code to create the heatmap

library(ggplot2)

all_data<- read.table("subset.txt", sep= "\t", header = T)
all_data.m <- melt(all_data)
p <- ggplot(all_data.m, aes( x=TCGA_ID , y= Gene_Name)) + geom_tile(aes(TCGA_ID) , colour= "blue") 

This is how the plot looks like enter image description here

My problems are:

1) How to expand the Y-axis so that the labels are not on top of each other

2) How to change the label on X-axis so that they are vertical and hence readable

3) How to change the colours based on different types of "Effect" . Do I need to use something like scale_fill_manual ?

My goal is to create a heatmap that looks like this

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
Jan Shamsani
  • 321
  • 2
  • 5
  • 14

1 Answers1

1

Not tested, but should work:

1) Change size of the font or the image, cannot see any other solution.

2) Add something along this:

p <- p + theme(axis.text.x  = element_text(angle=90, vjust=0.5, size=16))

More on axes: Axes_ggplot2

3) Add colour = Effect inside aes() in geom_tile().

m-dz
  • 2,342
  • 17
  • 29