Add absolute colours to heat map depending on range
0
0
Entering edit mode
2.1 years ago
amy__ ▴ 190

Hi,

I have a heatmap, and I wish to make the points from 0-30 white, 31-50 blue, 51+ dark blue.

However I do not want it to be a gradient, I want solid colours, does anyone have any ideas?

Here is a sample I think:

structure(list(chromosome = c("chr5", "chr5", "chr5", "chr5", 
"chr5", "chr5", "chr5", "chr5", "chr5", "chr5", "chr5", "chr5", 
"chr5", "chr5", "chr5", "chr5", "chr5", "chr5", "chr5", "chr5", 
"chr5", "chr5", "chr5", "chr5", "chr5"), start = 112754872:112754896, 
    end = 112754873:112754897, E132.H.001.1_S96_L008_ = c(171L, 
    172L, 172L, 183L, 184L, 186L, 186L, 187L, 190L, 185L, 192L, 
    197L, 199L, 202L, 202L, 204L, 204L, 205L, 208L, 213L, 211L, 
    214L, 217L, 222L, 221L), E132.H.002.1_S26_L002_ = c(92L, 
    96L, 97L, 97L, 99L, 99L, 102L, 107L, 111L, 112L, 114L, 115L, 
    118L, 118L, 119L, 119L, 120L, 124L, 127L, 125L, 125L, 125L, 
    124L, 125L, 125L)), row.names = c(NA, 25L), class = "data.frame")

From my entire dataframe I am able to produce a heatmap using this code:

df <- exon_noUTR_42_3113_index_samples_combined_APC_coverage

#For heatmap we just need count data, so we need to tell R we only want that information first
Counts <- data.frame(df$E132.H.001.1_S96_L008_, df$E132.H.002.1_S26_L002_, df$E132.H.004.1_S28_L002_, df$E132.H.005_S21_L002_, df$E132.H.006_S22_L002_, df$E132.H.007_S23_L002_, df$E132.H.008_S24_L002_, df$E132.H.009.1_S29_L002_, df$E132.H.010.1_S101_L008_, df$E132.H.011.1_S102_L008_, df$E132.H.012.1_S103_L008_, df$E132.H.013_S25_L002_, df$E132.H.014_S26_L002_, df$E132.H.015_S27_L002_, df$E132.H.016_S28_L002_, df$E132.H.017.1_S104_L008_, df$E132.H.018.1_S105_L008_, df$E132.H.019_S29_L002_, df$E132.H.020_S30_L002_, df$E218.A.001_S6_L001_, df$NG0921001_EKDN210018941.1A_HN2MGDSX2_L2_, df$NG0921002_EKDN210018942.1A_HN2MGDSX2_L3_, df$NG0921003_EKDN210018943.1A_HN2MGDSX2_L3_, df$NG0921004_EKDN210018944.1A_HMYL3DSX2_L4_,  df$NG0921005_EKDN210018945.1A_HN2MGDSX2_L2_, df$NG0921006_EKDN210018946.1A_HN2MGDSX2_L2_, df$NG0921007_EKDN210018947.1A_HN2MGDSX2_L3_, df$NG0921008_EKDN210018948.1A_HN2MGDSX2_L3_, df$NG0921009_EKDN210018949.1A_HN2MGDSX2_L3_, df$NG0921010_EKDN210018950.1A_HN2MGDSX2_L2_, df$NG0921011_EKDN210018951.1A_HN2MGDSX2_L3_, df$NG0921012_EKDN210018952.1A_HN2MGDSX2_L3_, df$NG0921013_EKDN210018953.1A_HN2MGDSX2_L2_, df$NG0921014_EKDN210018954.1A_HN2MGDSX2_L3_, df$NG0921015_EKDN210018955.1A_HN2MGDSX2_L3_, df$NG0921016_EKDN210018956.1A_HN2MGDSX2_L2_, df$NG0921017_EKDN210018957.1A_HN2MGDSX2_L2_, df$NG0921018_EKDN210018958.1A_HN2MGDSX2_L2_, df$NG0921019_EKDN210018959.1A_HN2MGDSX2_L2_, df$NG0921020_EKDN210018960.1A_HN2MGDSX2_L2_, df$NG0921021_EKDN210018961.1A_HN2MGDSX2_L2_, df$NG0921022_EKDN210018962.1A_HMYL3DSX2_L4_, df$NG0921024_EKDN210018964.1A_HMYL3DSX2_L4_, df$NG0921025_EKDN210018965.1A_HN2MGDSX2_L3_, df$NG0921026_EKDN210018966.1A_HN2MGDSX2_L2_, df$NG0921027_EKDN210018967.1A_HN2MGDSX2_L3_, df$NG0921028_EKDN210018968.1A_HN2MGDSX2_L3_, df$NG0921029_EKDN210018969.1A_HN2MGDSX2_L3_, df$NG0921030_EKDN210018970.1A_HN2MGDSX2_L2_, df$NG0921031_EKDN210018971.1A_HN2MGDSX2_L3_, df$NG0921032_EKDN210018972.1A_HN2MGDSX2_L3_, df$NG0921033_EKDN210018973.1A_HN2MGDSX2_L3_, df$NG0921035_EKDN210018974.1A_HMYL3DSX2_L4_, df$X_12M01471_L7_, df$X_12M04992_L6_, df$X_12M10775_L6_, df$X_12M10968_L1_, df$X_12M11537_L6_, df$X_13M01595_L1_, df$X_14M02599_L7_, df$X_14M03641_L1_, df$X_14M06940_L7_, df$X_14M11145_L7_, df$X_15M00729_L1_, df$X_15M11163_L7_, df$E036.H.002_CGTACTAG.GTAAGGAG_L001_, df$E036.H.003_AGGCAGAA.GTAAGGAG_L001_, df$E036.H.004_TCCTGAGC.GTAAGGAG_L001_, df$E036.H.005_GGACTCCT.GTAAGGAG_L001_, df$E036.H.006_TAGGCATG.GTAAGGAG_L001_, df$E036.H.009_GCTACGCT.GTAAGGAG_L001_, df$E036.H.011_AAGAGGCA.GTAAGGAG_L001_, df$E036.H.012_GTAGAGGA.GTAAGGAG_L001_, df$E036.H.013_TAAGGCGA.ACTGCATA_L007_, df$E036.H.014_CGTACTAG.ACTGCATA_L007_, df$E036.H.015_AGGCAGAA.ACTGCATA_L007_, df$E036.H.017_GGACTCCT.ACTGCATA_L007_, df$E036.H.018_TAGGCATG.ACTGCATA_L007_, df$E036.H.019_CTCTCTAC.ACTGCATA_L007_, df$E036.H.021_GCTACGCT.ACTGCATA_L007_, df$E036.H.023_AAGAGGCA.ACTGCATA_L007_, df$E036.H.025_GGACTCCT.GTAAGGAG_L007_, df$E036.H.027_CTCTCTAC.GTAAGGAG_L007_, df$E036.H.028_CAGAGAGG.GTAAGGAG_L007_, df$E036.H.029_TAAGGCGA.ACTGCATA_L006_, df$E036.H.030_CGTACTAG.ACTGCATA_L006_, df$E036.H.031_AGGCAGAA.ACTGCATA_L006_, df$E036.H.034_TAGGCATG.ACTGCATA_L006_, df$E036.H.035_CTCTCTAC.ACTGCATA_L006_, df$E036.H.036_CAGAGAGG.ACTGCATA_L006_, df$E036.H.039_CGAGGCTG.ACTGCATA_L006_, df$E036.H.040_TAAGGCGA.GTAAGGAG_L001_, df$E036.H.042_AGGCAGAA.GTAAGGAG_L001_, df$E036.H.043_TCCTGAGC.GTAAGGAG_L001_, df$E036.H.044_GGACTCCT.GTAAGGAG_L001_, df$E036_H_058_L003_, df$E036_H_059_L007_, df$E036_H_062_L003_, df$E036_H_065_L004_, df$E036_H_068_L007_, df$E036_H_070_L005_, df$E036_H_073_L006_, df$E036_H_075_L007_, df$E036_H_076_L006_, df$E036_H_077_L005_, df$E036_H_078_L006 , row.names =df$start)
Counts <- t(Counts)
Counts1 <- as.matrix(Counts)

png("ALL_Jasmine_practice_heatmap_exons_allsamples.png")

#Plot basic heatmap
pheatmap (Counts1, cluster_rows = F, cluster_cols = F, show_rownames = T, color = colorRampPalette(c("white", "blue", "darkblue"))(50), fontsize = 4)
dev.off()

and I am returned:

As you can see it is a gradient from 0-700 which the colour gradually changing, I don't want this. I would like 0-30 white, 31-50 blue, 51+ dark blue.

The sample names are not as blurry when I save as pdf

Thanks! Amy

heatmap pheatmap • 712 views
ADD COMMENT
0
Entering edit mode

enter image description here

ADD REPLY
0
Entering edit mode

Please read existing solutions first and then say where you get stuck: https://stackoverflow.com/questions/23938889/how-to-create-discrete-legend-in-pheatmap

ADD REPLY
0
Entering edit mode

I have not worked with pheatmap before, but if it accepts discrete input, you could just use cut() on your numerical values to make them discrete:

heatmap_values  <- rnorm(100,35,10)
cut(heatmap_values,breaks=c(0,30,50,Inf), include.lowest=TRUE)
ADD REPLY

Login before adding your answer.

Traffic: 2484 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6