Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I am trying to generate a heatmap using the function pheatmap(). But I get an error saying there are NA/NaN/Inf in the dataframe. I checkt it but there are no NA/NaN/Inf values in it..
This function worked before, so I do not see what I am doing wrong... Anyone any advise?
heat<-pheatmap(mat, kmeans_k = NA, breaks = NA, border_color= "grey60",cellwidth = 5, cellheight = 0.05, scale = "none", cluster_rows = TRUE,
cluster_cols = TRUE, clustering_distance_rows = "euclidean",
clustering_distance_cols = "euclidean", clustering_method = "complete",
cutree_rows = 1, cutree_cols = 1,
legend_labels = NA, annotation_row = NA, annotation_col = pd,
annotation = pd, annotation_colors = anno_colors, annotation_legend = TRUE,
annotation_names_row = TRUE, annotation_names_col = TRUE,
drop_levels = TRUE, show_rownames = F, show_colnames = T, main = NA, fontsize = 4,
fontsize_row = 4, fontsize_col = 4,
display_numbers = F, number_format = "%.2f", number_color = "grey30",
fontsize_number = 0.8 * fontsize, gaps_row = NULL, gaps_col = NULL,
labels_row = NULL, labels_col = NULL, filename = NA, width = NA,
height = NA, silent = FALSE)
Warning in dist(mat, method = distance) : NAs introduced by coercion
Error in hclust(d, method = method) :
NA/NaN/Inf in foreign function call (arg 10)
–
One of the probable causes of these error and warnings is the presence of a non-numeric vector in the matrix mat
.
For example, the first four columns in the iris
data frame are numeric vectors, and the fifth one is a character vector. If you include all the columns as the input for pheatmap
, the error and the warning message will pop up:
pheatmap(as.matrix(iris)) # failed.
#Error in hclust(d, method = method) :
# NA/NaN/Inf in foreign function call (arg 10)
#In addition: Warning messages:
#1: In dist(mat, method = distance) : NAs introduced by coercion
#2: In dist(mat, method = distance) : NAs introduced by coercion
If you include only the numeric columns, the function is executed with no error or warning
pheatmap(as.matrix(iris[,1:4])) # succeeded.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.