简体   繁体   中英

R Studio: Overlay heatmaps

I am very new to coding and ran into a problem for which I am not able to find the solution on the internet.

I have two matrices of data that I would like to combine into one heatmap. The matrices contain red and green fluorescence intensities of cells in time. I would like the heatmap colors to reflect both of the fluorescence intensities (white or black when both are low, red when red is high, green when green is high and yellow when both are low).

Creating a heatmap from the ratio between red and green is similar to what I want, but does not give any information about the absolute fluorescence intensity.

I can make two separate heatmaps and overlay them in Illustrator, but this 1. is less elegant, 2. does not allow me to cluster the cells and 3. when making the colors transparent in illustrator, the combination of red and green becomes brown in stead of yellow and both colors are very faint.

I am now trying to summarize the two values I have into one value. As far as I have figured out, this is only possible by creating an RGB value. But now that I have the RGB values for each timepoint, I am not able to get them into a plot.

Code:

Plotting the ratios in a heatmap:

heatmap.2(ratio_narm,
      trace="none",
      col = col,
      breaks = breaks,
      dendrogram='none',
      Rowv="NA",
      )

Plotting with ggplot with (melted) RGB data:

ggplot(data=RGB, aes(x=RGB$Timepoint, y=RGB$`Track ID`, fill=RGB$`RGB value`))

You can follow this approach. It will find low or high values in both matrices and set predefined values.

# data
set.seed(12385)
m1 <- matrix(runif(100),10,10)
m2 <- matrix(runif(100),10,10)
# thresholds
low <- 0.2
high <- 0.8
# matrix with values 0 (both are low), 0.5 (both are average), 1 (both are high)
m3 <- matrix(rep(0.5,100),10,10)
# set the groups by filtering
m3[ m1 < low & m2 < low ] <- 0
m3[ m1 > high & m2 > high ] <- 1
# low in m1, not considering m2
m3[ m1 < low  ] <- 0.75
# or low in m1, but normal in m2
m3[ m1 < low & (m2 > low & m2 < high) ] <- 0.75
# ... you can define more conditions as you like

# plot the heatmap
heatmap.2(m3,
          scale="none",trace="none",
          col = c("black","grey","red","yellow"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM