Adding data values on geom_barh chart in facet_plot

290 views
Skip to first unread message

Jane Rasmussen

unread,
Mar 5, 2017, 11:19:40 AM3/5/17
to ggtree
Hi Guangchuang et al, 

Is it possible to plot max value of a bar column onto the barchart in facet_plot?
I was thinking something similar to this.


tr <- rtree(30)
p <- ggtree(tr)
df <- data.frame(id = rep(tr$tip.label, each=2),
                     value = abs(rnorm(60, mean=100, sd=50)),
                     category = rep(LETTERS[1:2], 30))

sum_value <- df %>%
        group_by(id) %>%
        summarize(total = sum(value))
    
p3 <- facet_plot(p, panel = 'Stacked Barplot', data = df,
                     geom = geom_barh,
                     mapping = aes(x = value, fill = as.factor(category)),
                     stat='identity' ) + theme_tree2() +
        geom_text(aes(total, id, label = total), data = sum_value)

Sincerely,
Jane

Yu, Guangchuang

unread,
Mar 5, 2017, 9:08:07 PM3/5/17
to Jane Rasmussen, ggtree
p3 <- facet_plot(p, panel = 'Stacked Barplot', data = df,
                     geom = geom_barh,
                     mapping = aes(x = value, fill = as.factor(category)),
                     stat='identity'
 ) + theme_tree2() 
facet_plot(p3, geom=geom_text, mapping=aes(x=total+20, label=round(total)), data=sum_value, panel='Stacked Barplot')
Adding a layer to a specific panel was supported in facet_plot, if you specific the panel name to the one you want to add.





--
G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
 
Homepage: https://guangchuangyu.github.io/ggtree
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree+unsubscribe@googlegroups.com.
To post to this group, send email to bioc-...@googlegroups.com.
Visit this group at https://groups.google.com/group/bioc-ggtree.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/19e84168-78ba-4574-b695-bf608b816745%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, PhD Candidate
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages