Description Usage Arguments Value Examples
To compare network attributes and shape between etworks created by different network methods, plot networks in same manner, using one graph as default layout for all networks. 2 graphs are used as input: graph of one network, graph of network used to compare between. Output is network in same layout as comparison network.
1 |
g |
Graph |
g_orig_for_layout |
Graph used to compare with. |
physeq |
Phyloseq |
type |
What to plot (choose between samples or taxa). Default: samples. |
color |
Color of nodes (choose between rank levels) |
shape |
Shape of nodes |
point_size |
Size of nodes |
alpha |
Transparency of node color |
label |
Label of nodes |
hjust |
Adjust plot |
line_weight |
Weight of edges |
line_color |
Color of edges |
line_alpha |
Transparency of edge color |
layout.method |
Layout method for network |
title |
Title of network plot |
Returns network plot (ggplot object) in specified graph layout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (g, g_orig_for_layout, physeq = NULL, type = "samples",
color = NULL, shape = NULL, point_size = 4, alpha = 1, label = "value",
hjust = 1.35, line_weight = 0.5, line_color = color, line_alpha = 0.4,
layout.method = layout.fruchterman.reingold, title = NULL)
{
if (vcount(g) < 2) {
stop("The graph you provided, `g`, has too few vertices. \n Check your graph, or the output of `make_network` and try again.")
}
if (type %in% c("taxa", "species", "OTUs", "otus", "otu")) {
type <- "taxa"
}
edgeDF <- data.frame(get.edgelist(g))
edgeDF$id <- 1:length(edgeDF[, 1])
vertDF <- layout.method(g_orig_for_layout)
colnames(vertDF) <- c("x", "y")
vertDF <- data.frame(value = get.vertex.attribute(g, "name"),
vertDF)
if (!is.null(physeq)) {
extraData <- NULL
if (type == "samples" & !is.null(sample_data(physeq,
FALSE))) {
extraData = data.frame(sample_data(physeq))[as.character(vertDF$value),
, drop = FALSE]
}
else if (type == "taxa" & !is.null(tax_table(physeq,
FALSE))) {
extraData = data.frame(tax_table(physeq))[as.character(vertDF$value),
, drop = FALSE]
}
if (!is.null(extraData)) {
vertDF <- data.frame(vertDF, extraData)
}
}
graphDF <- merge(reshape2::melt(edgeDF, id = "id"), vertDF,
by = "value")
p <- ggplot(vertDF, aes(x, y))
p <- p + theme_bw() + theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.text.x = element_blank(),
axis.text.y = element_blank(), axis.title.x = element_blank(),
axis.title.y = element_blank(), axis.ticks = element_blank(),
panel.border = element_blank())
p <- p + geom_point(aes_string(color = color, shape = shape),
size = point_size, na.rm = TRUE)
if (!is.null(label)) {
p <- p + geom_text(aes_string(label = label), size = 2,
hjust = hjust, na.rm = TRUE)
}
p <- p + geom_line(aes_string(group = "id", color = line_color),
graphDF, size = line_weight, alpha = line_alpha, na.rm = TRUE)
if (!is.null(title)) {
p <- p + ggtitle(title)
}
return(p)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.