YuLab-SMU / aplot

Decorate a plot with associated information
https://yulab-smu.top/aplot
92 stars 14 forks source link

zero_range error in 0.1.10 #24

Closed m3hdad closed 1 year ago

m3hdad commented 1 year ago

I get the following error in 0.1.10 but everything works fine in 0.1.8 version. downgrading for now!

library(ggplot2)
library(aplot)

p <- p4 |> insert_left(p1,width = .5)
Error in if (zero_range(as.numeric(limits))) { : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In zero_range(as.numeric(limits)) : NAs introduced by coercion
GuangchuangYu commented 1 year ago

pls provide a reproducible example.

m3hdad commented 1 year ago

Thanks for prompt reply. @GuangchuangYu could you provide a link so I can share my objects. p1 and p4 are rather complex to share a reproducible code.

Thanks,

GuangchuangYu commented 1 year ago

pls send to guangchuangyu AT gmail.com

m3hdad commented 1 year ago

It's all in your hands!

xiangpin commented 1 year ago

it also doesn't work fine in 0.1.8 version on my platform. But I find the p1 is not a ggtree object, which might cause the issue. The following codes should work. I hope it can help you.

library(ggplot2)
 library(aplot)
 packageVersion("aplot")

 p1 <- readRDS("p1.rds")
 module_names <- readRDS("module_names.rds")
 p4 <- readRDS('p4.rds')

 #p4 |> insert_left(p1, width = .5)

 f1 <- module_names %>%
     data.frame(value=.) %>%
     dplyr::mutate(group=gsub(' .*','',value)) %>%
     ggplot(aes(x=0, y = value, fill = I(group))) +
     geom_tile() +
     theme(
       axis.ticks = element_blank(),
       axis.title = element_blank(),
       axis.text.x = element_blank(),
       axis.text.y = element_text(hjust = 0),
       panel.grid=element_blank(),
       panel.background = element_blank(),
       plot.background=element_blank()
     )

 p.tr <- p4[[1]]$data %>%
     tidyr::pivot_wider(id_cols=module, names_from='traits_of_interest', values_from='correlation') %>%
     tibble::column_to_rownames(var='module') %>%
     dist() %>%
     hclust(method='ave') %>%
     ggtree::ggtree(hang=-1)

 p.end <- (p4[[1]] + coord_cartesian(expand=F)) %>%
     insert_left(f1 + coord_cartesian(expand=F), width=.05) %>%
     insert_left(p.tr, width=.2)

捕获

m3hdad commented 1 year ago

thanks for looking into this. I believe you are using R 4.2.3 and something has changed since 4.2.1. We can close the issue since it is not related to aplot.