Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert_left can not work #40

Open
franco-ye opened this issue Jan 18, 2025 · 3 comments
Open

insert_left can not work #40

franco-ye opened this issue Jan 18, 2025 · 3 comments

Comments

@franco-ye
Copy link

Image

Dear Uncle Y:
I keep getting this error when using inset_left; But I don't know why it happened. Is it a bug ?

@GuangchuangYu
Copy link
Member

you need to provide an example to produce your issue.

@franco-ye
Copy link
Author

Thanks for Uncle Y's prompt reply!

When running simple test data, I did not trigger any errors; however, I encounter errors when performing complex operations.

This is a demo:

library(ggtree)
library(ggstance)
####----Success----####
set.seed(2020-03-27)
x <- rtree(10)
d <- data.frame(taxa=x$tip.label, value = abs(rnorm(10)))
p <- ggtree(x) + geom_tiplab() + xlim(NA, 3)
p2 <- ggplot(d, aes(value, taxa)) + geom_col() + 
  scale_x_continuous(expand=c(0,0))

p2 %>% insert_left(p)
####----error----####
p <- ggtree(x,branch.length = "none")  +
  xlim(NA,40)

get_taxa_name(p) -> gene_name
heatmap_df <- data.frame(
  gene_name = factor(gene_name, levels = rev(gene_name), ordered = T),
  Environment = "Environment",
  Variable1 = c(rep("A", 2), rep("B", 4), rep("C", 2), rep("D", 2)),
  Location = "Location",
  Variable2 = c(rep("a", 2), rep("b", 4), rep("c", 2), rep("d", 2)),
  none = "none",
  Variable3 = NA,
  OGT = "OGT",
  Variable4 = seq(33, 100, length.out = 10)
) 

ggplot(data = heatmap_df) + 
  geom_tile(aes(x = Environment, y = gene_name, fill = Variable1),
            color = "black", alpha = 0.7, linewidth = 0.5) + 
  scale_fill_jco(name = "Environment") + 
  new_scale_fill() +
  geom_tile(aes(x = Location, y = gene_name, fill = Variable2),
            color = "black", alpha = 0.7, linewidth = 0.5) + 
  scale_fill_ucscgb(name = "Location")+ 
  geom_tile(aes(x = none, y = gene_name),
            fill = NA) + 
  new_scale_fill() + 
  geom_tile(aes(x = OGT, y = gene_name, fill = Variable4),
            alpha = 0.85, color = "black") + 
  scale_fill_continuous(type = "viridis", name = "OGT") + 
  labs(x = "", y = "") + 
  scale_x_discrete(position = "top",
                   breaks = c("Environment", "Location", "OGT"),
                   labels = c("Environment", "Location", "OGT")) +
  theme_bw() + 
  theme(
    panel.border = element_blank(),
    panel.grid = element_blank(),
    axis.ticks = element_blank(),
    axis.text.y = element_blank(),
    axis.text.x = element_text(angle=90, hjust = 0)
  ) -> heatmap.p
heatmap.p %>% insert_left(.,p, width = 0.85)

@GuangchuangYu
Copy link
Member

Image

all is functioning properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants