This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Heatmap value gradient

Hi,

I am trying to create a heatmap that doesn't use gradient for values. There are only 2 numbers: 3 and 1. I want 3 to be a specific color and 1 to be another color. And this would also be reflected in the heatmap too.

data.heatmap <- ggplot(data = Good1_Poor3, mapping = aes (x = sample_id, y = Gene)) + geom_tile(aes(fill = response..Good1_Int2_Poor3.)) +  scale_fill_gradient2() +
  theme(axis.text.y = element_text(size = 4))
genomics r dna-seq heatmap

1 answer

You need to change atleast two things here

  1. write qplot instead of ggplot.
  2. add scale_fill_manual(values=c("3"="green", "1"="red")) at the end of your command

It should look like this:

qplot(data=Good1_Poor3,
      x=sample_id,
      y=Gene,
      fill=factor(response),
      geom="tile")+scale_fill_manual(values=c("3"="green", "1"="red"))

Log in to answer this question.