簡體   English   中英

熱圖返回錯誤:“ x”必須是數字矩陣,但x是數字矩陣

[英]Heatmap returning error: 'x' must be a numeric matrix, but x is a numeric matrix

我正在嘗試創建六個站點上物種豐富度的熱圖。 我有一個站點與物種,數字豐度數據的矩陣。

但是,當我運行代碼時,R返回一個錯誤,表明我的矩陣是非數字的。 誰能解決這個問題? 我感到難過。

導出的數據鏈接: log_mean_wide

工作方式:

lrc <- rainbow(nrow(log_mean_wide), start = 0, end = .3)
lcc <- rainbow(ncol(log_mean_wide), start = 0, end = .3)


logmap <- heatmap(log_mean_wide, col = cm.colors(256), scale = "column", 
               RowSideColors = lrc, ColSideColors = lcc, margins = c(5, 10),
               xlab = "species", ylab = "Site", 
               main = "heatmap(<Auckland Council MCI data 1999, habitat:bank>, ..., scale = \"column\")")

錯誤消息:熱圖錯誤(log_mean_wide,Rowv = NA,Colv = NA,col = cm.colors(256),:'x'必須是數字矩陣

log_heatmap <- heatmap(log_mean_wide, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10)) #same error

is.numeric(log_mean_wide) #[1] FALSE
is.character(log_mean_wide) #[1] FALSE
is.factor(log_mean_wide) #[1] FALSE
is.logical(log_mean_wide) #[1] FALSE
is.integer(log_mean_wide) #[1] FALSE

?!?!

dims <- dim(log_mean_wide)
log_mean_matrix <- as.numeric(log_mean_wide) 
dim(log_mean_matrix) <- dims

錯誤:(列表)對象無法強制輸入“ double”類型

str(log_mean_wide)將物種顯示為數字,將站點顯示為字符-為什么這不起作用?

storage.mode(log_mean_wide) <- "numeric" 

storage.mode(log_mean_wide)<-“ numeric”:(list)對象中的錯誤無法強制輸入'double'類型

有兩個問題:

  1. 第一列log_mean_wide$Site是非數字的。
  2. heatmap僅接受matrix作為輸入數據(不接受data.frame )。

要解決這些問題,您可以執行以下操作(請注意,熱圖中有很多混亂情況):

# Store Site information as rownames
df <- log_mean_wide;
rownames(df) <- log_mean_wide[, 1];

# Remove non-numeric column
df <- df[, -1];

# Use as.matrix to convert data.frame to matrix
logmap <- heatmap(
    as.matrix(df),
    col = cm.colors(256),
    scale = "column",
    margins = c(5, 10),
    xlab = "species", ylab = "Site",
    main = "heatmap(<Auckland Council MCI data 1999, habitat:bank>, ..., scale = \"column\")")

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM