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
problems with facet_plot #120
Comments
|
Re: [GuangchuangYu/ggtree] problems with facet_plot (#120)
If a paste the code
tr <- rtree(30)
p <- ggtree(tr)
d1 <- data.frame(id=tr$tip.label, location=sample(c("GZ", "HK", "CZ"), 30, replace=TRUE))
p1 <- p %<+% d1 + geom_tippoint(aes(color=location))
d2 <- data.frame(id=tr$tip.label, val=rnorm(30, sd=3))
p2 <- facet_plot(p1, panel="dot", data=d2, geom=geom_point,
aes(x=val), color='firebrick') + theme_tree2()
d3 <- data.frame(id = rep(tr$tip.label, each=2),
value = abs(rnorm(60, mean=100, sd=50)),
category = rep(LETTERS[1:2], 30))
p3 <- facet_plot(p2, panel = 'Stacked Barplot', data = d3,
geom = geom_barh,
mapping = aes(x = value, fill = as.factor(category)),
stat='identity' )
I get "Error in facet_plot(p2, panel = "Stacked Barplot", data = d3, geom = geom_barh, :
object 'geom_barh' not found", and I do not know why. That was the reason to switch to geom_bar instead.
Apologies. I am using ggtree 1.6.11
Manuel Aira
Grupo de Ecologia Animal
Departamento de Ecoloxia e Bioloxia Animal
Universidade de Vigo
mailto:aira@uvigo.es
===8<==============Texto del mensaje original===============
Closed #120.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
===8<===========Fin del texto del mensaje original===========
|
Version: ggtree 1.6.11 I can confirm the issues reported by @pedres. When using the example code provided on https://guangchuangyu.github.io/2016/10/facet_plot-a-general-solution-to-associate-data-with-phylogenetic-tree/ you get an error message:
The following error message is displayed:
If we use geom_bar instead, no error message is displayed, but the plot looks as reported by @pedres. |
an excerpt from the post http://guangchuangyu.github.io/2016/10/facet_plot-a-general-solution-to-associate-data-with-phylogenetic-tree/
Did both of you really read the post? AND you also ignore my guidance of reporting an issue. |
Ok, my fault - indeed, if the library "ggstance" is loaded, the posted coded runs smoothly. So here again the code that should run (directly taken from http://guangchuangyu.github.io/2016/10/facet_plot-a-general-solution-to-associate-data-with-phylogenetic-tree/):
Apologies for any inconvenience. |
Re: [GuangchuangYu/ggtree] problems with facet_plot (#120)
Thanks four your help. Not your fault, it was completely mine.
Manuel Aira
Grupo de Ecologia Animal
Departamento de Ecoloxia e Bioloxia Animal
Universidade de Vigo
mailto:aira@uvigo.es
===8<==============Texto del mensaje original===============
Ok, my fault - indeed, if the library ggstance is loaded, the posted coded runs smoothly. So here again the code that should run (directly taken from http://guangchuangyu.github.io/2016/10/facet_plot-a-general-solution-to-associate-data-with-phylogenetic-tree/):
library(ggtree)
library(ggstance) #Without this library the code won't work
tr <- rtree(30)
p <- ggtree(tr)
d1 <- data.frame(id=tr$tip.label, location=sample(c("GZ", "HK", "CZ"), 30, replace=TRUE))
p1 <- p %<+% d1 + geom_tippoint(aes(color=location))
d2 <- data.frame(id=tr$tip.label, val=rnorm(30, sd=3))
p2 <- facet_plot(p1, panel="dot", data=d2, geom=geom_point,
aes(x=val), color='firebrick') + theme_tree2()
d3 <- data.frame(id = rep(tr$tip.label, each=2),
value = abs(rnorm(60, mean=100, sd=50)),
category = rep(LETTERS[1:2], 30))
p3 <- facet_plot(p2, panel = 'Stacked Barplot', data = d3,
geom = geom_barh,
mapping = aes(x = value, fill = as.factor(category)),
stat='identity' )
p3
Apologies for any inconvenience.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
===8<===========Fin del texto del mensaje original===========
|
rm(list=ls(all=TRUE));library(ggstance);library(phylobase);library(ggtree);library(cowplot);library(reshape2);library(betapart);library(grid);library(gridExtra);library(tidyr);library(phyloseq);library(ggplot2);library(plyr);library(vegan);library(nlme);library(picante);library(nortest);library(multcomp);library(data.table); library(phangorn);library(car);library(codyn)
theme_set(theme_bw())
### the example form website works
tr <- rtree(60)
p <- ggtree(tr)
d1 <- data.frame(id=tr$tip.label, location=sample(c("GZ", "HK", "CZ"), 60, replace=TRUE))
p1 <- p %<+% d1 + geom_tippoint(aes(color=location))
d2 <- data.frame(id=tr$tip.label, val=rnorm(60, sd=3))
p2 <- facet_plot(p1, panel="dot", data=d2, geom=geom_point,aes(x=val), color='firebrick') + theme_tree2()
d3 <- data.frame(id = rep(tr$tip.label, each=2),value = abs(rnorm(60, mean=100, sd=50)),category = rep(LETTERS[1:2], 60))
p3 <- facet_plot(p2, panel = 'Stacked Barplot', data = d3,geom = geom_barh,mapping = aes(x = value, fill = as.factor(category)),stat='identity' )
p3
summary(d3)
id value category
t1 : 2 Min. : 2.319 A:60
t10 : 2 1st Qu.: 60.910 B:60
t11 : 2 Median : 87.020
t12 : 2 Mean : 95.611
t13 : 2 3rd Qu.:132.496
t14 : 2 Max. :208.377
(Other):108
datosRAREF<-import_biom(file.choose());datosRAREF
relabund = transform_sample_counts(datosRAREF, function(x) x / sum(x) )
repet<-c(1,1,2,3,4,5,1,2,3,4,1,5,1,2,3,4,5,2,1,2,3,4,5,3,4,5,2,3,4,5)
tiempo<-c("07days","14days","14days","14days","14days","14days","28days","28days","28days","28days","0days","28days","42days","42days","42days","42days","42days","0days","91days","91days","91days","91days","91days","0days","0days","0days","07days","07days","07days","07days")
factores<-as.data.frame(cbind(repet,tiempo)); rm(repet);rm(tiempo)
summarize_taxa <- function(counts, taxonomy) {
if(is.matrix(taxonomy)) {
#message('multiple taxonomies')
alply(taxonomy, 2, summarize_taxa, counts = counts, .dims = TRUE)
} else if(is.matrix(counts)) {
#message('multiple counts')
require('plyr')
apply(counts, 2, summarize_taxa, taxonomy = taxonomy)
} else {
#message('summarize')
tapply(counts, taxonomy, sum)
}
}
ot <- as(otu_table(relabund), 'matrix')
tax <- as.data.frame(tax_table(relabund))
tax$phylum<-tax$Rank2
tax <- subset(tax, select = phylum)
tax<-as.matrix(tax)
abundancias<-summarize_taxa(ot, tax)
filos<-data.frame(t(abundancias$phylum*100))
filos1<-filos[,colMeans(filos) < 1]; lowabundance<-rowSums(filos1);rm(filos1) ## los que tienen abundancias menor de 1
filos2<-filos[,colMeans(filos) > 1] ## los que tienen abundancias mayor de 1
filos<-data.frame(cbind(factores,filos2,lowabundance));rm(filos2)
meltedfilos <- melt(filos, id.vars=c("repet", "tiempo"))
meansfilos <- ddply(meltedfilos, c("tiempo", "variable"), summarise, mean=mean(value))
filosXX<-cbind(muestras=rownames(filos),filos)
meltedfilosXX <- gather(filosXX, filos, abundancias, Actinobacteria:lowabundance, factor_key=TRUE)
meltedfilosXXX<-cbind(id=meltedfilosXX$muestras,meltedfilosXX);meltedfilosXXX <- subset(meltedfilosXXX, select = c(id,filos,abundancias))
tr2<-rtree(30,tip.label = rownames(filos)
tr2gg <- ggtree(tr2)
tr2ggbarplot <- facet_plot(tr2gg, panel = 'Stacked Barplot', data = meltedfilosXXX,geom = geom_barh,mapping = aes(x = abundancias, fill = as.factor(filos)),stat='identity' )
summary(meltedfilosXXX)
id filos abundancias
AB10C : 6 Actinobacteria :30 Min. : 0.0000
AB11 : 6 Bacteroidetes :30 1st Qu.: 0.6001
AB12 : 6 Firmicutes :30 Median : 3.2598
AB13 : 6 Proteobacteria :30 Mean :16.6667
AB14 : 6 Verrucomicrobia:30 3rd Qu.:38.0269
AB15 : 6 lowabundance :30 Max. :66.0884
(Other):144
|
I have the most recent version of ggtree (1.6.11), but I still have problems to reproduce the output of example from facet_plot for stacked barplots. This is what I get, which is strange, if I type the code from http://guangchuangyu.github.io/2016/10/facet_plot-a-general-solution-to-associate-data-with-phylogenetic-tree/
I am trying to join a tree (a hc object formatted as ggtree object) with an stacked barplot of abundances. My tree has 30 tips, and my dataset to stack as 180 rows, each tip has 6 values,like
1 AB10C Actinobacteria 2.228632578
2 AB10C Bacteroidetes 3.730753128
3 AB10C Firmicutes 3.904868286
4 AB10C Proteobacteria 3.734883721
5 AB10C Verrucomicrobia 4.807334326
6 AB10C lowabundance 3.043275942
When I type the code below I obtain the example2, in which appears the tree but not the barplot
arbolbarplot<-facet_plot(arbolbien, panel = 'Stacked Barplot', data = meltedfilosXXX, geom = geom_bar, mapping = aes(x = abundancias, fill = as.factor(filos)), stat='identity' )
The barplot I would like to join to the tree is
ggplot(meltedfilosXXX, aes(x=id, y=abundancias, fill=filos)) + geom_bar(stat="identity") + coord_flip() + ylab("Relative abundance")
Thank you very much for your help
Below I paste R session info
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C LC_TIME=Spanish_Spain.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] car_2.1-4 phangorn_2.1.1 data.table_1.10.4 multcomp_1.4-6 TH.data_1.0-8 MASS_7.3-45 survival_2.40-1 mvtnorm_1.0-6 nortest_1.0-4 picante_1.6-2 ape_4.1
[12] nlme_3.1-131 vegan_2.4-2 lattice_0.20-34 permute_0.9-4 plyr_1.8.4 phyloseq_1.14.0 tidyr_0.6.1 gridExtra_2.2.1 betapart_1.4-1 reshape2_1.4.2 cowplot_0.7.0
[23] ggtree_1.6.11 ggplot2_2.2.1 phylobase_0.8.2
loaded via a namespace (and not attached):
[1] minqa_1.2.4 colorspace_1.3-2 htmlTable_1.9 futile.logger_1.4.3 XVector_0.10.0 RcppArmadillo_0.7.700.0.0 GenomicRanges_1.22.4
[8] base64enc_0.1-3 MatrixModels_0.4-1 AnnotationDbi_1.32.3 xml2_1.1.1 codetools_0.2-15 splines_3.3.3 bold_0.4.0
[15] geneplotter_1.48.0 knitr_1.15.1 ade4_1.7-5 Formula_1.2-1 jsonlite_1.3 nloptr_1.0.4 pbkrtest_0.4-7
[22] annotate_1.48.0 cluster_2.0.5 httr_1.2.1 backports_1.0.5 assertthat_0.1 Matrix_1.2-8 lazyeval_0.2.0
[29] acepack_1.4.1 htmltools_0.3.5 quantreg_5.29 prettyunits_1.0.2 tools_3.3.3 igraph_1.0.1 gtable_0.2.0
[36] taxize_0.8.4 dplyr_0.5.0 fastmatch_1.1-0 Rcpp_0.12.9 Biobase_2.30.0 Biostrings_2.38.4 RJSONIO_1.3-0
[43] multtest_2.26.0 biom_0.3.12 iterators_1.0.8 stringr_1.2.0 lme4_1.1-12 XML_3.98-1.5 zlibbioc_1.16.0
[50] zoo_1.7-14 scales_0.4.1 rcdd_1.1-11 parallel_3.3.3 SummarizedExperiment_1.0.2 sandwich_2.3-4 SparseM_1.76
[57] lambda.r_1.1.9 RColorBrewer_1.1-2 memoise_1.0.0 rpart_4.1-10 reshape_0.8.6 latticeExtra_0.6-28 stringi_1.1.2
[64] RSQLite_1.1-2 genefilter_1.52.1 S4Vectors_0.8.11 foreach_1.4.3 checkmate_1.8.2 BiocGenerics_0.16.1 BiocParallel_1.4.3
[71] geometry_0.3-6 GenomeInfoDb_1.6.3 rncl_0.8.2 labeling_0.3 htmlwidgets_0.8 magrittr_1.5 DESeq2_1.10.1
[78] R6_2.2.0 IRanges_2.4.8 Hmisc_4.0-2 DBI_0.6 foreign_0.8-67 mgcv_1.8-17 nnet_7.3-12
[85] tibble_1.2 futile.options_1.0.0 uuid_0.1-2 progress_1.1.2 RNeXML_2.0.7 locfit_1.5-9.1 digest_0.6.12
[92] xtable_1.8-2 stats4_3.3.3 munsell_0.4.3 magic_1.5-6 quadprog_1.5-5
The text was updated successfully, but these errors were encountered: