Learn R Programming

grapherator (version 1.0.0)

plot.grapherator: Visualize graph.

Description

plot.grapherator generates a scatterplot of the nodes in the Euclidean plane. Additionally, the edge weights are visualized. In case of one weight per edge either a histogram or an empirical distribution function is drawn. For graphs with two weights per edge a scatterplot is used.

Usage

# S3 method for grapherator
plot(x, y = NULL, show.cluster.centers = TRUE,
  highlight.clusters = FALSE, show.edges = TRUE,
  weight.plot.type = "histogram", ...)

Arguments

x

[grapherator] Graph.

y

Not used at the moment.

show.cluster.centers

[logical(1)] Display cluster centers? Default is TRUE. This option is ignored silently if the instance is not clustered.

highlight.clusters

[logical(1)] Shall nodes be coloured by cluster membership? Default is FALSE.

show.edges

[logical(1)] Display edges? Keep in mind, that the number of edges is \(O(n^2)\) where \(n\) is the number of nodes. Default is TRUE.

weight.plot.type

[character(1)] Type of visualization which should be used for weights in case x has only as single weight attached to each edge. Either “histogram” or “ecdf” (empirical distribution function) are possible choices. Default is histogram.

...

[any] Not used at the moment.

Value

[list] A list of ggplot objects with components pl.weights (scatterplot of edge weights) and eventually pl.coords (scatterplot of nodes). The latter is NULL, if graph has no associated coordinates.

Examples

Run this code
# NOT RUN {
g = graph(0, 100)
g = addNodes(g, n = 25, generator = addNodesGrid)
g = addEdges(g, generator = addEdgesDelauney)
g = addWeights(g, generator = addWeightsDistance, method = "manhattan")
# }
# NOT RUN {
pls = plot(g, weight.plot.type = "ecdf")
# }
# NOT RUN {
g = addWeights(g, generator = addWeightsRandom,
  method = rpois, lambda = 0.1)
# }
# NOT RUN {
pls = plot(g, show.edges = FALSE)
# }
# NOT RUN {
g = graph(0, 100)
g = addNodes(g, n = 25, generator = addNodesGrid)
g = addNodes(g, n = 9, by.centers = TRUE, generator = addNodesGrid,
  lower = c(0, 0), upper = c(7, 7))
g = addEdges(g, generator = addEdgesDelauney)
g = addWeights(g, generator = addWeightsCorrelated, rho = -0.8)
# }
# NOT RUN {
do.call(gridExtra::grid.arrange, plot(g, show.edges = FALSE))
do.call(gridExtra::grid.arrange, plot(g, show.edges = TRUE,
  show.cluster.centers = FALSE))
# }

Run the code above in your browser using DataLab