RNA Seq Heatmaps
1
0
Entering edit mode
5.6 years ago

Deal all, Kindly help me when I am trying to plot heatmap by using log2 fold change values an error " 'x' must be a numeric matrix" shows up"

head(all.values)
  gene_id G1_Control G2_C0ntrol G3_Control   G2_Exp   G3_Exp    G1C_G2E  G1C_G3E  G2C_G2E   G2C_G3E  G3C_G2E  G3C_G3E  G1C_G2C  G1C_G3C
1    Atg3  0.0000000    0.00000   22.12740  0.00000  0.00000          0  0.00000        0         0        0        0        0  1.20074
2   Kdm2b 50.8615000   35.06180    6.86875 47.91910 32.16190 -0.0859727 32.16190 0.450701 -0.124548  1.11477  0.53952 0.536674 0.782525
3     Lta 11.8152000   10.54070    0.00000 12.06340  9.70298  0.0299925  9.70298 0.194659 -0.119478 0.812517  0.49838 0.164666      inf
4    Nsmf  0.0638957    0.00000    1.44001  0.00000  0.00000     #NAME?  0.00000        0         0        0        0      inf  2.28763
5   Taf11  7.0308800    3.61325    7.92353  5.99789  2.64062  -0.229251  2.64062 0.731158 -0.452418  2.05837 0.874799 0.960409 0.949555
6    Rgs4 15.3025000   12.90490    6.79880 15.92480 14.13800   0.057505 14.13800 0.303361  0.131664  1.00706 0.835363 0.245856 0.724393
   G2C_G3C
1        0
2 0.664068
3 0.617858
4        0
5  1.32722
6 0.703699

data1<-as.matrix(all.values)
library("ggplot2", lib.loc="~/R/win-library/3.5")
heatmap(all.values)
Error in heatmap(all.values) : 'x' must be a numeric matrix
RNA-Seq • 1.3k views
ADD COMMENT
1
Entering edit mode

I edited your post to make the code more clear via the use of the 101 010 button.

ADD REPLY
1
Entering edit mode

There is a #NAME? in G1C_G2E column. Can you fix it? challagandla.anil. ggplot may not be good for heatmap. You should be trying other packages such as complexheatmap, pheatmap etc. However, with OP data and ggplot, you can have tile plot:

df1=read.csv("test.txt", sep = "\t", strip.white = T, stringsAsFactors = F)
row.names(df1)=df1[,1]
df1=df1[,-1]
df1[df1=="#NAME?"] <- NA
df1[df1=="Inf"] <- NA
library(tidyverse)
library(ggplot2)
df2=gather(df1,"Sample","Exp")

ggplot(df2, aes(Sample,as.integer(Exp),fill=as.integer(Exp)))+
    geom_tile()+
    scale_fill_gradient(name="Expression",low = "green",high = "red")+
    theme_bw()+
    ylab("Expression")+
    theme(axis.text.y = element_blank(),
          axis.ticks.y = element_blank(),
          axis.text.x = element_text(angle=-45, hjust=-0.1, size = 14),
          )

Rplot01

ADD REPLY
0
Entering edit mode

Thank you a lot, I am very new for all of these and trying my best to learn, it solved my problem.

ADD REPLY
3
Entering edit mode
5.6 years ago

There are a few things wrong in your code. Firstly, heatmap() is not part of ggplot2. heatmap() should be installed by default in R. heatmap.2(), on the other hand, is part of gplots package.

Simply try:

rownames(all.values) <- all.values[ ,1]

all.values <- all.values[ ,-1]

# convert Infinite values and '#NAME?' to NA
df[df=="#NAME?"] <- NA
df[df=="inf"] <- NA

heatmap(data.matrix(all.values))
ADD COMMENT
1
Entering edit mode

Yes, I have to learn basics first before getting into real problems and thank you for letting me know. data.matrix() worked instead of >as.matrix() .

ADD REPLY

Login before adding your answer.

Traffic: 2906 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