Skip to content

Commit

Permalink
Fixing plot.mcGP
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 5, 2017
1 parent d1c03b9 commit 6172690
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
28 changes: 14 additions & 14 deletions R/plotGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@
#' have coordinates, additionally a scatterplot of the nodes in the euclidean
#' plane is generated.
#'
#' @template arg_mcGP
#' @param show.cluster.centers [\code{logical(1)}]\cr
#' Display cluster centers?
#' Default is \code{TRUE}. This option is ignored silently if the instance is not clustered.
#' @param ... [any]\cr
#' Not used at the moment.
#' @param x Not used at the moment.
#' @param x [\code{mcGP}]\cr
#' Multi-objective graph problem.
#' @param y Not used at the moment.
#' @return [\code{list}] A list of \code{\link[ggplot2]{ggplot}} objects with components
#' \code{pl.weights} (scatterplot of edge weights) and eventually \code{pl.coords} (scatterplot of
#' nodes). The latter is \code{NULL}, if \code{graph} has no associated coordinates.
#' @export
plot.mcGP = function(graph, show.cluster.centers = TRUE, x=NULL, y=NULL, ...) {
plot.mcGP = function(x, y=NULL, show.cluster.centers = TRUE, ...) {

assertFlag(show.cluster.centers)

pl.coords = NULL
n.nodes = graph$n.nodes
n.clusters = graph$n.clusters
n.weights = graph$n.weights
n.nodes = x$n.nodes
n.clusters = x$n.clusters
n.weights = x$n.weights
if (n.weights > 2L)
stopf("plot.mcGP: More than 2 weights are currently not supported.")
if (!is.null(graph$coordinates)) {
dd = as.data.frame(graph$coordinates)
if (!is.null(x$coordinates)) {
dd = as.data.frame(x$coordinates)
names(dd) = c("x1", "x2")
if (!is.null(graph$membership))
dd$Cluster = as.factor(graph$membership)
if (!is.null(x$membership))
dd$Cluster = as.factor(x$membership)
pl.coords = ggplot2::ggplot(dd, aes_string(x = "x1", y = "x2"))
pl.coords = if (n.clusters > 0L) pl.coords +
ggplot2::geom_point(aes_string(colour = "Cluster")) else pl.coords + ggplot2::geom_point()
if (n.clusters > 0L & show.cluster.centers) {
ddc = as.data.frame(graph$center.coordinates)
ddc = as.data.frame(x$center.coordinates)
names(ddc) = c("x1", "x2")
pl.coords = pl.coords +
ggplot2::geom_point(data = ddc, colour = "black", size = 3)
Expand All @@ -49,16 +49,16 @@ plot.mcGP = function(graph, show.cluster.centers = TRUE, x=NULL, y=NULL, ...) {
ggplot2::xlab(expression(x[1])) +
ggplot2::ylab(expression(x[2]))
}
weights1 = graph$weights[[1L]]
weights2 = graph$weights[[2L]]
weights1 = x$weights[[1L]]
weights2 = x$weights[[2L]]

weights1 = as.numeric(weights1[upper.tri(weights1)])
weights2 = as.numeric(weights2[upper.tri(weights2)])

dd = data.frame(w1 = weights1, w2 = weights2)
pl.weights = ggplot2::ggplot(dd, aes_string(x = "w1", y = "w2")) + ggplot2::geom_point()
pl.weights = pl.weights +
ggplot2::ggtitle("Edge weights", subtitle = collapse(paste(names(dd), graph$weight.types, sep = " : "), sep = ","))
ggplot2::ggtitle("Edge weights", subtitle = collapse(paste(names(dd), x$weight.types, sep = " : "), sep = ","))
pl.weights = pl.weights + xlab(expression(w[1])) + ylab(expression(w[2]))


Expand Down
11 changes: 4 additions & 7 deletions man/plot.mcGP.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6172690

Please sign in to comment.