YuLab-SMU / aplot

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

Can't save two aplots in one pdf #10

Closed Ekie22 closed 2 years ago

Ekie22 commented 3 years ago

Hello,

it is not possible to write two aplots on separate pages in one pdf. Only the last plot is shown.

library(ggplot2)
library(ggtree)
library(aplot)

set.seed(2019-10-31)
tr <- rtree(10)

d1 <- data.frame(
  label = c(tr$tip.label[sample(5, 5)], "A"),
  value = sample(1:6, 6))

d2 <- data.frame(
  label = rep(tr$tip.label, 5),
  category = rep(LETTERS[1:5], each=10),
  value = rnorm(50, 0, 3)) 

g <- ggtree(tr) + geom_tiplab(align=TRUE)

p1 <- ggplot(d1, aes(label, value)) + geom_col(aes(fill=label)) + 
  geom_text(aes(label=label, y= value+.1)) +
  coord_flip() + theme_tree2() + theme(legend.position='none')

p2 <- ggplot(d2, aes(x=category, y=label)) + 
  geom_tile(aes(fill=value)) + scale_fill_viridis_c() + 
  theme_tree2() 
p3 <- ggplot(d2, aes(x=category, y=label)) + 
  geom_tile(aes(fill=value)) + 
  theme_tree2()

pdf("test_aplot.pdf", onefile = TRUE)
p2 %>% insert_left(g) %>% insert_right(p1, width=.5) #
p3 %>% insert_left(g) %>% insert_right(p1, width=.5)
dev.off()

Is there a way to resolve that? Thanks

GuangchuangYu commented 2 years ago

cannot reproduce this issue.

image