YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/treedata-book/
821 stars 172 forks source link

Warnings generated by normal use of ggheatmap function #577

Open AlexSCFraser opened 1 year ago

AlexSCFraser commented 1 year ago

I am getting a lot of warnings from using the ggtree() and gheatmap() functions under normal use. My plots look fine, but I was concerned I was doing something wrong. Investigating further, I actually get the same warnings when I run example code straight from the treedata book. I've got the latest version of ggtree from bioconductor (3.8.0), and latest R(4.3.1) and Rstudio(2023.6.1).

The code I'm using is from this example:

library(ggtree)
library(ggplot2)

nwk <- system.file("extdata", "sample.nwk", package="treeio")

tree <- read.tree(nwk)
circ <- ggtree(tree, layout = "circular")

df <- data.frame(first=c("a", "b", "a", "c", "d", "d", "a", 
                        "b", "e", "e", "f", "c", "f"),
                 second= c("z", "z", "z", "z", "y", "y", 
                        "y", "y", "x", "x", "x", "a", "a"))
rownames(df) <- tree$tip.label

df2 <- as.data.frame(matrix(rnorm(39), ncol=3))
rownames(df2) <- tree$tip.label
colnames(df2) <- LETTERS[1:3]

p1 <- gheatmap(circ, df, offset=.8, width=.2,
               colnames_angle=95, colnames_offset_y = .25) +
    scale_fill_viridis_d(option="D", name="discrete\nvalue")

library(ggnewscale)
p2 <- p1 + new_scale_fill()
gheatmap(p2, df2, offset=15, width=.3,
         colnames_angle=90, colnames_offset_y = .25) +
    scale_fill_viridis_c(option="A", name="continuous\nvalue")

And the output when i run this in RStudio:

> nwk <- system.file("extdata", "sample.nwk", package="treeio")
> 
> tree <- read.tree(nwk)
> circ <- ggtree(tree, layout = "circular")
> 
> df <- data.frame(first=c("a", "b", "a", "c", "d", "d", "a", 
+                          "b", "e", "e", "f", "c", "f"),
+                  second= c("z", "z", "z", "z", "y", "y", 
+                            "y", "y", "x", "x", "x", "a", "a"))
> rownames(df) <- tree$tip.label
> 
> df2 <- as.data.frame(matrix(rnorm(39), ncol=3))
> rownames(df2) <- tree$tip.label
> colnames(df2) <- LETTERS[1:3]
> 
> 
> p1 <- gheatmap(circ, df, offset=.8, width=.2,
+                colnames_angle=95, colnames_offset_y = .25) +
+     scale_fill_viridis_d(option="D", name="discrete\nvalue")
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
ℹ invalid tbl_tree object. Missing column: label.
ℹ invalid tbl_tree object. Missing column: label.
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale.
Warning messages:
1: In min(x[, 2]) : no non-missing arguments to min; returning Inf
2: In min(x[, 2]) : no non-missing arguments to min; returning Inf
3: In min(x[, 2]) : no non-missing arguments to min; returning Inf
4: In min(x[, 2]) : no non-missing arguments to min; returning Inf
> 
> 
> library(ggnewscale)
> p2 <- p1 + new_scale_fill()
> gheatmap(p2, df2, offset=15, width=.3,
+          colnames_angle=90, colnames_offset_y = .25) +
+     scale_fill_viridis_c(option="A", name="continuous\nvalue")
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
ℹ invalid tbl_tree object. Missing column: label.
ℹ invalid tbl_tree object. Missing column: label.
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale.
Warning messages:
1: In min(x[, 2]) : no non-missing arguments to min; returning Inf
2: In min(x[, 2]) : no non-missing arguments to min; returning Inf
3: In min(x[, 2]) : no non-missing arguments to min; returning Inf
4: In min(x[, 2]) : no non-missing arguments to min; returning Inf

The generated plot is correct, exactly matching the book's plot, but these warnings are very confusing to new users of the ggtree library and it would be nice if it did not generate all these warnings when it is used properly. This might be something related to my setup, since a colleague does not get the invalid edge matrix, invalid tbl_tree object, or non-missing argument to min errors, but she does get the fill scale errors.

It would be nice if there were no errors in normal operation on well formatted code(which I assume the example code in the treedata book is) and I'm not sure if this is system or setup specific or a general problem with the library.

am-epi commented 11 months ago

Thanks for your post - I have just had the same issue come up when running gheatmap also. I needed to update a plot I made a month ago and noticed these warning signs coming up this time round which weren't there the first time I made the heatmap plot. I wonder if it has something to do with the new R update?

Glad I found your message as I've just spent an hour trying to troubleshoot what had gone wrong....