bc-anaisabel / juniperus_paper

Pipeline for analyzing Illumina MiSeq paired-end data of fungal communities
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

2_Juniperus_Alpha_Diversity.R - add legend titles (labs) #5

Closed bc-anaisabel closed 4 years ago

bc-anaisabel commented 4 years ago

How can I add a legent title to this plot:

par(mfrow=c(1,2), xpd=T) gplot(as.one.mode(network_host), displaylabels = TRUE, label=rownames(network_host), gmode="graph", label.cex=0.6, vertex.col = color$Family, vertex.cex=2)

Screen Shot 2020-10-08 at 7 12 41 PM

I would like to end with something similar to this

Screen Shot 2020-10-08 at 7 05 33 PM

The data to work on it is created from:

#Select data
subset <- subset_taxa(subset.texcoco.binary, Trophic %in% c("a__am"))
subset

subset <-subset.texcoco.binary.beta

subset<-subset.myc

subset

#Subset
Top <- names(sort(taxa_sums(subset), TRUE)[1:500])
ent <- prune_taxa(Top, subset)
ent
taxa_sums(ent)

taxa_sums(subset) [1:10]
ent <- prune_taxa(taxa_sums(ent) > 0, ent)
any(taxa_sums(subset) == 0)
taxa_sums(ent) [1:10]
ent

#Merge by category 
nw <-merge_samples(subset, group = "Host")
network_host <- as.data.frame(otu_table(nw))
is.matrix(network_host)

#vectors
taxa_names(subset)
color_vector <- c("f__ Glomeraceae", "f__ Claroideoglomeraceae", "f__ Acaulosporaceae", "f__ Diversisporaceae", "f__ Gigasporaceae", "f__ Ambisporaceae", "f__ Paraglomeraceae", "f__ Unknown")
color<-as.matrix(tax_table(subset))
color<-as.data.frame(color)

#Gplot
gplot(network_host, thresh = 0.2, displaylabels = FALSE, vertex.col = color$Trophic)
network_host

#Merge more than one category 

sample_variables(subset)

variable1 = as.character(get_variable(subset, "Host"))
variable2 = as.character(get_variable(subset, "Site"))

sample_data(subset)$NewPastedVar <- mapply(paste0, variable1, variable2, 
                                            collapse = "_")
nw2<- merge_samples(subset, "NewPastedVar")

network_host <- as.data.frame(otu_table(nw2))