#' Add positions to the nodes
#'
#' Aggregate positions to the nodes into mclean output
#'
#' @param network list; output from \code{mclean} function.
#' @param data matrix or data frame with postitions to add into the \code{network} object.
#' @param labels character string specifying the lables of each data element.
#' @param x character string specifying the x position of each data element.
#' @param y character string specifying the y position of each data element.
#'
#' @return It adds two new columns \code{x} and \code{y} in the \code{node} object.
#'
#' @author Daniel Alcaide, \email{daniel.alcaide@@esat.kuleuven.be}
#' @references Alcaide D, Aerts J. (2018) MCLEAN: Multilevel Clustering Exploration As Network. PeerJ Computer Science 4:e145 \url{https://doi.org/10.7717/peerj-cs.145}
#'
#' @examples
#' data("synthetic_distances")
#' require(Rtsne)
#' tsne <- Rtsne(synthetic_distances, dims = 2, is_distance = TRUE, verbose=FALSE,
#' perplexity = (nrow(as.matrix(synthetic_distances))/3)-1)
#' tsne_output = cbind(rownames(as.matrix(synthetic_distances)), as.data.frame(tsne$Y));
#' colnames(tsne_output) = c("V1", "V2", "V3")
#' output = mclean(distance_matrix = synthetic_distances, threshold = 187, method = "single")
#' plot_network( add_positions_nodes(output, tsne_output, labels = "V1", x = "V2", y = "V3") )
#' @export
add_positions_nodes = function(network, data, labels = "nodes", x = "x", y = "y"){
data = data[,c(labels, x, y)]
colnames(data) = c("nodes", "x", "y")
network$nodes = merge(network$nodes, data)
return(network)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.