Gitte Brinch Andersen
2013-Jun-25 18:49 UTC
[R] Heatmap with error message: `x' must be a numeric matrix
Hi I am trying to do a heatmap, but I can't see what I am doing wrong. I get the error message: `x' must be a numeric matrix, but as far as I know I have changed my data into a matrix. The dataset I have in my example of my run is only a small part. I have around 1000 rows in total. I have checked that none of the rows contains any letters etc, and I have removed the rows where some of the samples contain NA. So I can't see why the numbers aren't numeric. I have tried to change the numbers to contain dots instead of commas, but this still gives me the same error. I hope someone can give me a hint to what I am doing wrong! I am still very new to R, and apologize in advance if this is just some simple stupid mistake. My R run is this: #Load in data>data<-read.table("/Users/gban/Desktop/Probes_for_heatmap_35_meth_diff_both_hypo_and_hypermeth_Gene&probenames.txt",sep="\t",header=TRUE,row.names=1)# Throw out rows with missing values.>data = na.omit(data)>dataOS_Tumor1_08_14985_2_3 OS_Tumor2_08_226869_1 CHST3_cg04268405_1 0,950380605 0,76433753 DLX5_cg19962750_2 0,93111825 0,753845234 ZIC4_cg12892506_3 0,860337466 0,696149332 DLX5_cg05597836_4 0,906981714 0,664148911 ARHGEF7_cg09129334_6 0,88102921 0,726231077 ZIC4_cg02387803_7 0,770987986 0,568085839 ZIC4_cg05855917_8 0,880514891 0,681148663 DLX5_cg13286614_9 0,855132688 0,592368469 ZIC4_cg04556126_10 0,907405655 0,718858033 LOC145845_cg25718467_11 0,893492688 0,793191968 ZIC4_cg08393041_12 0,911133787 0,678042743 SNED1_cg03785076_13 0,862060883 0,70294155 C10orf116_cg01004363_14 0,858555164 0,553920222 DLX5_cg20250426_15 0,903165828 0,64976206 EPHX3_cg16184495_16 0,927538308 0,519523714 SNED1_cg21304158_17 0,762270611 0,647588457 EN1_cg12418535_19 0,790529679 0,318880892 RTKN_cg00689340_20 0,941714187 0,675243565 SNED1_cg16937168_21 0,894421593 0,821448724 CD93_cg12873119_22 0,86949625 0,676389091 RRN3P2_cg00525931_23 0,862670615 0,855822961 GPBAR1_cg18581950_24 0,800216557 0,810012301 SPARCL1_cg15552249_25 0,815666773 0,837099021 HOXD12_cg23130254_26 0,840109076 0,502896181 ZIC4_cg08889797_27 0,779606392 0,591615859 ESRP2_cg06723863_28 0,655488067 0,47819514 ZIC4_cg16790847_29 0,735676228 0,611372155 PFDN5_cg16309127_30 0,753348167 0,630504254 ARHGEF7_cg05776861_31 0,951737748 0,926613919 TBX15_cg24720355_32 0,906521431 0,364984479 FER1L5_cg01876130_33 0,601084686 0,805388591 HOXD12_cg18022224_34 0,865974739 0,543178066 DLX6AS_cg26251506_35 0,804479354 0,538022928 GSTM5_cg05376982_36 0,733426641 0,552089202 ZIC4_cg12976081_37 0,464939006 0,551218578 HOXB4_cg02132714_38 0,798491712 0,718121432 HOXD10_cg17489939_39 0,970868858 0,790134913 C10orf116_cg12261786_40 0,727394677 0,573072856 SPARCL1_cg19466563_41 0,79754226 0,722582785 HOXD12_cg03964958_42 0,778450531 0,679889139 HOXA5_cg09549073_43 0,4652904 0,377825589 ZIC4_cg00334063_44 0,783052842 0,634682328 TBX15_cg16990168_45 0,893463329 0,235197972 #Load gplot package>library(gplots)#Make the data into a matrix>data1<-as.matrix(data)>data1OS_Tumor1_08_14985_2_3 OS_Tumor2_08_226869_1 CHST3_cg04268405_1 "0,950380605" "0,76433753" DLX5_cg19962750_2 "0,93111825" "0,753845234" ZIC4_cg12892506_3 "0,860337466" "0,696149332" DLX5_cg05597836_4 "0,906981714" "0,664148911" ARHGEF7_cg09129334_6 "0,88102921" "0,726231077" ZIC4_cg02387803_7 "0,770987986" "0,568085839" ZIC4_cg05855917_8 "0,880514891" "0,681148663" DLX5_cg13286614_9 "0,855132688" "0,592368469" ZIC4_cg04556126_10 "0,907405655" "0,718858033" LOC145845_cg25718467_11 "0,893492688" "0,793191968" ZIC4_cg08393041_12 "0,911133787" "0,678042743" SNED1_cg03785076_13 "0,862060883" "0,70294155" C10orf116_cg01004363_14 "0,858555164" "0,553920222" DLX5_cg20250426_15 "0,903165828" "0,64976206" EPHX3_cg16184495_16 "0,927538308" "0,519523714" SNED1_cg21304158_17 "0,762270611" "0,647588457" EN1_cg12418535_19 "0,790529679" "0,318880892" RTKN_cg00689340_20 "0,941714187" "0,675243565" SNED1_cg16937168_21 "0,894421593" "0,821448724" CD93_cg12873119_22 "0,86949625" "0,676389091" RRN3P2_cg00525931_23 "0,862670615" "0,855822961" GPBAR1_cg18581950_24 "0,800216557" "0,810012301" SPARCL1_cg15552249_25 "0,815666773" "0,837099021" HOXD12_cg23130254_26 "0,840109076" "0,502896181" ZIC4_cg08889797_27 "0,779606392" "0,591615859" ESRP2_cg06723863_28 "0,655488067" "0,47819514" ZIC4_cg16790847_29 "0,735676228" "0,611372155" PFDN5_cg16309127_30 "0,753348167" "0,630504254" ARHGEF7_cg05776861_31 "0,951737748" "0,926613919" TBX15_cg24720355_32 "0,906521431" "0,364984479" FER1L5_cg01876130_33 "0,601084686" "0,805388591" HOXD12_cg18022224_34 "0,865974739" "0,543178066" DLX6AS_cg26251506_35 "0,804479354" "0,538022928" GSTM5_cg05376982_36 "0,733426641" "0,552089202" ZIC4_cg12976081_37 "0,464939006" "0,551218578" HOXB4_cg02132714_38 "0,798491712" "0,718121432" HOXD10_cg17489939_39 "0,970868858" "0,790134913" C10orf116_cg12261786_40 "0,727394677" "0,573072856" SPARCL1_cg19466563_41 "0,79754226" "0,722582785" HOXD12_cg03964958_42 "0,778450531" "0,679889139" HOXA5_cg09549073_43 "0,4652904" "0,377825589" ZIC4_cg00334063_44 "0,783052842" "0,634682328" TBX15_cg16990168_45 "0,893463329" "0,235197972" heatmap.2(data1, col=redgreen(75), scale="row", key=T, keysize=1.5,density.info="none", trace="none",cexCol=0.9, labRow=NA) Fejl i heatmap.2(data1, col = redgreen(75), scale = "row", key = T, : `x' must be a numeric matrix Many thanks! Kind regards Gitte Brinch Andersen [[alternative HTML version deleted]]
Rui Barradas
2013-Jun-25 19:51 UTC
[R] Heatmap with error message: `x' must be a numeric matrix
Hello, Your data has commas as decimal points, R uses the period. So the data is read in as strings, not numbers. You can change this by using argument 'dec' of read.table: ?read.table read.table(...etc..., dec = ",") Or you can replace the commas with periods: data[] <- sapply(data, function(x) as.numeric(sub(",", "\\.", x))) data1 <- as.matrix(data) heatmap.2(...) # No errors Hope this helps, Rui Barradas Em 25-06-2013 19:49, Gitte Brinch Andersen escreveu:> Hi > > I am trying to do a heatmap, but I can't see what I am doing wrong. I get the error message: `x' must be a numeric matrix, but as far as I know I have changed my data into a matrix. > > The dataset I have in my example of my run is only a small part. I have around 1000 rows in total. I have checked that none of the rows contains any letters etc, and I have removed the rows where some of the samples contain NA. So I can't see why the numbers aren't numeric. > > I have tried to change the numbers to contain dots instead of commas, but this still gives me the same error. > > I hope someone can give me a hint to what I am doing wrong! > > I am still very new to R, and apologize in advance if this is just some simple stupid mistake. > > My R run is this: > > #Load in data >> data<-read.table("/Users/gban/Desktop/Probes_for_heatmap_35_meth_diff_both_hypo_and_hypermeth_Gene&probenames.txt",sep="\t",header=TRUE,row.names=1) > > > > # Throw out rows with missing values. >> data = na.omit(data) > > > >> data > OS_Tumor1_08_14985_2_3 OS_Tumor2_08_226869_1 > CHST3_cg04268405_1 0,950380605 0,76433753 > DLX5_cg19962750_2 0,93111825 0,753845234 > ZIC4_cg12892506_3 0,860337466 0,696149332 > DLX5_cg05597836_4 0,906981714 0,664148911 > ARHGEF7_cg09129334_6 0,88102921 0,726231077 > ZIC4_cg02387803_7 0,770987986 0,568085839 > ZIC4_cg05855917_8 0,880514891 0,681148663 > DLX5_cg13286614_9 0,855132688 0,592368469 > ZIC4_cg04556126_10 0,907405655 0,718858033 > LOC145845_cg25718467_11 0,893492688 0,793191968 > ZIC4_cg08393041_12 0,911133787 0,678042743 > SNED1_cg03785076_13 0,862060883 0,70294155 > C10orf116_cg01004363_14 0,858555164 0,553920222 > DLX5_cg20250426_15 0,903165828 0,64976206 > EPHX3_cg16184495_16 0,927538308 0,519523714 > SNED1_cg21304158_17 0,762270611 0,647588457 > EN1_cg12418535_19 0,790529679 0,318880892 > RTKN_cg00689340_20 0,941714187 0,675243565 > SNED1_cg16937168_21 0,894421593 0,821448724 > CD93_cg12873119_22 0,86949625 0,676389091 > RRN3P2_cg00525931_23 0,862670615 0,855822961 > GPBAR1_cg18581950_24 0,800216557 0,810012301 > SPARCL1_cg15552249_25 0,815666773 0,837099021 > HOXD12_cg23130254_26 0,840109076 0,502896181 > ZIC4_cg08889797_27 0,779606392 0,591615859 > ESRP2_cg06723863_28 0,655488067 0,47819514 > ZIC4_cg16790847_29 0,735676228 0,611372155 > PFDN5_cg16309127_30 0,753348167 0,630504254 > ARHGEF7_cg05776861_31 0,951737748 0,926613919 > TBX15_cg24720355_32 0,906521431 0,364984479 > FER1L5_cg01876130_33 0,601084686 0,805388591 > HOXD12_cg18022224_34 0,865974739 0,543178066 > DLX6AS_cg26251506_35 0,804479354 0,538022928 > GSTM5_cg05376982_36 0,733426641 0,552089202 > ZIC4_cg12976081_37 0,464939006 0,551218578 > HOXB4_cg02132714_38 0,798491712 0,718121432 > HOXD10_cg17489939_39 0,970868858 0,790134913 > C10orf116_cg12261786_40 0,727394677 0,573072856 > SPARCL1_cg19466563_41 0,79754226 0,722582785 > HOXD12_cg03964958_42 0,778450531 0,679889139 > HOXA5_cg09549073_43 0,4652904 0,377825589 > ZIC4_cg00334063_44 0,783052842 0,634682328 > TBX15_cg16990168_45 0,893463329 0,235197972 > > #Load gplot package >> library(gplots) > > #Make the data into a matrix >> data1<-as.matrix(data) > >> data1 > > OS_Tumor1_08_14985_2_3 OS_Tumor2_08_226869_1 > CHST3_cg04268405_1 "0,950380605" "0,76433753" > DLX5_cg19962750_2 "0,93111825" "0,753845234" > ZIC4_cg12892506_3 "0,860337466" "0,696149332" > DLX5_cg05597836_4 "0,906981714" "0,664148911" > ARHGEF7_cg09129334_6 "0,88102921" "0,726231077" > ZIC4_cg02387803_7 "0,770987986" "0,568085839" > ZIC4_cg05855917_8 "0,880514891" "0,681148663" > DLX5_cg13286614_9 "0,855132688" "0,592368469" > ZIC4_cg04556126_10 "0,907405655" "0,718858033" > LOC145845_cg25718467_11 "0,893492688" "0,793191968" > ZIC4_cg08393041_12 "0,911133787" "0,678042743" > SNED1_cg03785076_13 "0,862060883" "0,70294155" > C10orf116_cg01004363_14 "0,858555164" "0,553920222" > DLX5_cg20250426_15 "0,903165828" "0,64976206" > EPHX3_cg16184495_16 "0,927538308" "0,519523714" > SNED1_cg21304158_17 "0,762270611" "0,647588457" > EN1_cg12418535_19 "0,790529679" "0,318880892" > RTKN_cg00689340_20 "0,941714187" "0,675243565" > SNED1_cg16937168_21 "0,894421593" "0,821448724" > CD93_cg12873119_22 "0,86949625" "0,676389091" > RRN3P2_cg00525931_23 "0,862670615" "0,855822961" > GPBAR1_cg18581950_24 "0,800216557" "0,810012301" > SPARCL1_cg15552249_25 "0,815666773" "0,837099021" > HOXD12_cg23130254_26 "0,840109076" "0,502896181" > ZIC4_cg08889797_27 "0,779606392" "0,591615859" > ESRP2_cg06723863_28 "0,655488067" "0,47819514" > ZIC4_cg16790847_29 "0,735676228" "0,611372155" > PFDN5_cg16309127_30 "0,753348167" "0,630504254" > ARHGEF7_cg05776861_31 "0,951737748" "0,926613919" > TBX15_cg24720355_32 "0,906521431" "0,364984479" > FER1L5_cg01876130_33 "0,601084686" "0,805388591" > HOXD12_cg18022224_34 "0,865974739" "0,543178066" > DLX6AS_cg26251506_35 "0,804479354" "0,538022928" > GSTM5_cg05376982_36 "0,733426641" "0,552089202" > ZIC4_cg12976081_37 "0,464939006" "0,551218578" > HOXB4_cg02132714_38 "0,798491712" "0,718121432" > HOXD10_cg17489939_39 "0,970868858" "0,790134913" > C10orf116_cg12261786_40 "0,727394677" "0,573072856" > SPARCL1_cg19466563_41 "0,79754226" "0,722582785" > HOXD12_cg03964958_42 "0,778450531" "0,679889139" > HOXA5_cg09549073_43 "0,4652904" "0,377825589" > ZIC4_cg00334063_44 "0,783052842" "0,634682328" > TBX15_cg16990168_45 "0,893463329" "0,235197972" > > heatmap.2(data1, col=redgreen(75), scale="row", key=T, keysize=1.5,density.info="none", trace="none",cexCol=0.9, labRow=NA) > Fejl i heatmap.2(data1, col = redgreen(75), scale = "row", key = T, : > `x' must be a numeric matrix > > Many thanks! > > Kind regards > > Gitte Brinch Andersen > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >