YuLab-SMU / aplot

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

Missing drawing components when combining aplot with geom_fruit #15

Closed dinhe878 closed 2 years ago

dinhe878 commented 2 years ago

Hi,

I've been struggling to generate a particular composite plot. Nearly all is good except one scale went missing. Hard to explain with text so here are some figures:

Tree figure -

onTip_data <- genus_metadata %>%
  select(c(Diet_specialization, Num_species)) %>%
  rownames_to_column("tip_lable")

g <- ggtree(full_host_genus.tre, right=T, branch.length = 'none') %<+% 
  onTip_data + 
  geom_tippoint(aes(size = Num_species, shape = Diet_specialization)) +
  scale_size(trans="exp", breaks=c(1,2,3)) +
  theme(legend.position = "left")

image

Then combining with a boxplot using geom_fruit -

g1 <- g + geom_fruit(data=all_metadata, 
                     geom=geom_boxplot,
                     aes(x=Shannon, y=genus),
                     pwidth=1, offset=0.2,
                     grid.params=list(alpha=.5),
                     axis.params=list(axis="x", text=c(0,1,2,3,4,5,6), text.size=2, vjust=1))

image

Finally combining with a barplot using aplot -

p <- plot_composition(genus_r70k_miAbundFamily.ps, 
                      taxonomic.level="Family", 
                      sample.sort=order_name_list)

p1 <- p + scale_fill_brewer("Microbiota (Family)", palette = "Paired") + 
  guides(fill = guide_legend(ncol = 1)) +
  labs(x="", y="Relative abundance") +
  scale_y_percent() + 
  coord_flip() + 
  theme_ipsum(grid="Y") +
  theme(axis.text.x = element_text(angle=35, hjust=1),
        axis.text.y = element_text(angle=0, hjust=1),
        legend.text = element_text(face = "italic"))

p1 %>% insert_left(g1, width=1)

image

As you can see that the scale lines from the "Shannon" boxplot are missing and it returned these warnings:

Warning messages: 1: Removed 9 rows containing missing values (geom_segment). 2: Removed 8 rows containing missing values (geom_segment). 3: Removed 7 rows containing missing values (geom_text).

I even try to manually add vertical lines to the final figure but no luck there. Advice please!

Many thanks! /Ding

GuangchuangYu commented 2 years ago

@xiangpin

xiangpin commented 2 years ago

This issue has been fixed by ggtreeExtra (>=1.4.1), which is the newest released version.

dinhe878 commented 2 years ago

Thanks a lot for the help. However, my issue persists. I've tried the latest version of ggtreeExtra (1.5.2) and it still produce the same plot with missing scale lines of the boxplot and the warning messages (one extra):

Warning messages: 1: Removed 9 rows containing missing values (geom_segment). 2: Removed 8 rows containing missing values (geom_segment). 3: Removed 7 rows containing missing values (geom_text). 4: Removed 1 rows containing missing values (geom_text).

I ended up instead, using cowplot package to "hard" align the figures.

ggdraw() + draw_plot(g1, x=0, y=.07, width=.3, height=.915) + draw_plot(p1, x=.25, y=0, width=.7, height=1)

GAGA_genus_TAXAbarplot_shannon

But I still think that it'd good to know what went wrong with my previous approach, if possible.

Many thanks again for making these great tools!

Best, Ding