Bug: Error in mat[, col.show] : incorrect number of dimensions in netVisual_heatmap
Closed this issue · 2 comments
emmanuel-contreras commented
When using the heatmap function and you only want to show one column or one row, R automatically converts a 1D vector to numeric and it throws the error below
Error in mat[, col.show] : incorrect number of dimensions
gg2 = netVisual_heatmap(cellchat,
measure='count',
sources.use = sources.use,
targets.use = targets.use,
row.show = sources.use, # these will throw an error if one dimensional
col.show = targets.us, # these will throw an error if one dimensional
color.heatmap = "Reds" ,
cluster.rows=FALSE,
cluster.cols = FALSE
)
The solution is to prevent the downcasting in the netVisual_heatmap function here:
Lines 1935 to 1943 in 1d9b7f5
by adding 'drop=F'
mat <- net
if (!is.null(row.show)) {
mat <- mat[row.show, , drop=F] # prevents downcasting to numeric
color.use.row <- color.use.row[row.show]
}
if (!is.null(col.show)) {
mat <- mat[, col.show, drop=F] # prevents downcasting to numeric
color.use.col <- color.use.col[col.show]
}
sqjin commented
@emmanuel-contreras Thanks! It was fixed now.
emmanuel-contreras commented
Awesome! and thanks for the great package!