Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dynamicGraphMain

Dynamic Graph


Description

Interactive plot for manipulating graphs.

Usage

dynamicGraphMain(vertexList = NULL, blockList = NULL, 
                 dg = NULL, object = NULL, objectName = NULL, 
                 control = dg.control(...), ...)

Arguments

vertexList

List of vertices (each of class containing the class dg.Vertex) created by returnVertexList or exported from dynamicGraphMain.

blockList

List of blocks (each of class dg.Block) created by setBlocks or exported from dynamicGraphMain.

dg

dg is an object of class dg.graphedges-class.

object

NULL, or object with the methods modifyModel and testEdge - for respectively updating the object when the graph is updated, and for computing the test statistic when an edge is labeled. The returned object from testEdge should have the methods label and width for extracting the label of a test for putting the label on the edge and for extracting the width for the edge. See dg.Model-class.

objectName

If set to a text string then the object is assigned with this name in .Global.Env when the object is updated.

control

Options for dynamicGraphMain, see dg.control.

...

Additional arguments.

Details

This is a dynamic plotting tool for handling graphs. The lay out of the graph can be edited by moving the vertices of the graph by the mouse, and edges can be added by clicking vertices and dropping by clicking the edges.

The function is incremental in the sense that the user can add a method for updating the model object of the window when the graph is updated, and a method for computing the test of an edge when the edge is clicked by the mouse.

Edges can be oriented, drawn by arrows.

Blocks can be used to define a causal structure of the variables represented by vertices, and edges between blocks are then oriented. Blocks can be given in a structure such that descendant blocks of a blocks also are closed when a block is closed.

A secondary set of vertices, factor vertices, can be used to represent hypergraphs.

"Slave graph windows" can be created: The windows will share vertices and blocks, thus when a vertex is moved in one window, the position of the vertex will also change in all slave windows. The edges are not shared among windows, since the individual windows will typical represent different models. Thus factors (vertices and edges) are not shared between graph windows.

Value

An object of class DynamicGraph-class (if not returnNull is TRUE) with the lists of vertices and blocks (block trees) of the dynamicGraph, and list of models, each (of class DynamicGraphModel-class) with the views of the model.

Each view (of class DynamicGraphView-class) of a model will hold the edges (edges between vertices, factors and blocks) and factor- and extra-vertices of the view, together with which vertices and blocks are visible in the view.

All object in the graph window:

  • Left click, hold and drag:The object will move.

  • Left click:Action to the object: Vertices, edges, and blocks will highlight, at vertices and blocks edges are added after highlighting, tests are computed for edge labels.

  • Left or right click, with SHIFT or/and CONTROL:The object will be marked.

  • Double left click:Action to object: Vertices and edges are deleted, blocks will close, closed blocks will open.

  • Right click:The pop up menu of the object will appear.

Vertices (vertices and factor vertices):

Right click the vertex to get the pop up menu of the vertex:

  • Highlight a vertex:For adding an edge - Left click the vertex.

  • Highlight a vertex:For adding to "selectedNodes" - Left or right click the vertex while holding SHIFT or/and CONTROL down.

  • Mark a vertex:For adding edges, etc. - Left or right click the vertex while holding SHIFT or/and CONTROL down.

  • Cancel highlighting:Left click (or drag) the vertex.

  • Add an edge:After first highlighting a vertex - Left click the other vertex.

  • Move a vertex:Left click and drag the vertex.

  • Move a vertex label:Left click and drag the label of the vertex.

  • Delete a vertex:Double left click the vertex.

  • Create new graph:A slave window with the vertex delete - Select "Drop vertex" from pop up menu at the vertex.

  • Change a vertex label:Double left click the label, and enter the new label in the appearing dialog window.

  • Delete a vertex label:Select "Delete vertex label" from the pop up menu at the vertex or at the vertex label.

  • Create new vertex:At mouse position - Middle click the canvas.

  • Create new vertex:At mouse position with the edge to last vertex - Double middle click the canvas.

The main menu "Variables":

  • Create new variable:With setting the class of the new vertex and defining an expression for updating the object - Select "Create new variable".

  • Display, add, a vertex:In the current window - Select "Select vertex among variables not displayed (here)".

  • Display, add, a vertex:In a slave window - Select "Select vertex among variables not displayed (slave)".

  • Export the vertex list:Select "Assign 'vertexList' in .GlobalEnv".

  • Export the labels:Select "Assign 'extraList' in .GlobalEnv".

Edges (edges to/from vertices, blocks and factors):

Right click the edge to get the pop up menu of the edge:

  • Highlight a edge:Left click the edge.

  • Highlight a edge:For adding to "selectedEdges" - Left or right click the edge while holding SHIFT or/and CONTROL down.

  • Add an edge:Left click first the vertex (or block) to highlight, and then left click other vertex (or block).

  • Delete an edge:And update in the current window - Double left click the edge.

  • Delete an edge:And create a slave graph with the resulting graph - Select "Drop edge" from the pop up menu at the edge.

  • Move an edge (2 vertices):Left click the edge and drag the edge.

  • Move an edge label:Left click the edge label and drag the label.

  • Set an edge label:Select "Set edge label" from the edge pop up menu.

  • Compute an edge label:Left click the edge label, or select "Compute edge label" from pop up menu at the edge.

  • Compute an edge label:Force computation for "harder models" - Double left click the edge label, or select "Force compute edge label" from pop up menu of the edge.

  • Delete an edge label:Triple left click the edge label, or select "Delete label of edge" from the pop up menu at the edge.

The main menu "Edges":

  • Delete all edge labels:Select "Delete all edge labels".

  • Export the edge list:Select "Assign 'edgeList' in .GlobalEnv".

Blocks, opened:

Right click the block label (or colored block canvas if drawBlockBackground is set to TRUE) to get the pop up menu of opened block:

  • Move a block:With its sub blocks and vertices - Left click the block label or colored block canvas and drag the block. [ Slow !!!]

  • Resize a block:Left click a block corner or a block edge and drag.

  • Minimize a block:With its sub blocks and vertices - Double left click the block label or the colored block canvas.

  • Maximize a block:Zoom to the block - Right click the block label or colored the block canvas and select "Maximize" in the appering popup menu.

  • Zoom out to the full graph:Right click the block label or colored block canvas and select "Redraw (Zoom to) full graph" in the appearing block pop up menu.

Blocks, closed:

Right click the block to get the pop up menu of the closed block:

  • Highlight a block:For adding edges from all vertices of the block to a vertex or a block - Left click the block.

  • Highlight a block:For adding to "selectedNodes" - Left or right click the block while holding SHIFT or/and CONTROL down.

  • Mark a block:For adding edges, etc. - Left or right click the block while holding SHIFT or/and CONTROL down.

  • Cancel highlighting:Of a block - Left click (or drag) the block.

  • Add edges:To all vertices of block after highlighting first a block or a vertex - Click the other block.

  • Move a closed block:Left click and drag the block.

  • Move a block label:Left click and drag the label of the block.

  • Open a closed block:Double left click the block.

  • Change a block label:Double left click the label of the closed block, and enter the new label in the appearing dialog window.

  • Delete a block label:Select "Delete label of block" from the pop up menu at the block or the block label.

The main menu "Blocks":

  • Export the block list:Select "Assign 'blockList' in .GlobalEnv".

  • Export the block edges:Select "Assign 'blockEdgeList' in .GlobalEnv".

Factor vertices:

Right click the factor vertex to get the pop up menu of the factor: Actions as for vertices. The main menu "Generators":

  • Export the factor vertices:Select "Assign 'factorVertexList' in .GlobalEnv".

  • Export the factor edges:Select "Assign 'factorEdgeList' in .GlobalEnv".

Factor edges:

Right click the factor edge to get the pop up menu of the factor edge: Actions are as for edges.

The panel for vertices:

  • Highlight vertex name for adding or deleting vertex: Left click the vertex name.

  • Delete or add vertices: Double left click a vertex name.

  • Popup menu for selected vertex: Click "Popup selected in panel" in "File Menu".

  • Dialog window for properties: Middle click vertex name.

The panel for blocks in tree and vertices:

  • Move vertex to other block: Left click the vertex name and drag to the other block.

  • Move block to other block: Left click the block name and drag to the other block.

  • Popup menu for selected vertex or block : Click "Popup selected in panel" in "File Menu".

The graph:

  • Create a slave window:Select "Make slave window: Same model".

  • Create a slave window:Select "Make slave window: Copy model".

  • Switch class of view:Select "Set class of graph window".

  • Refresh:Faster fix of "corrupted" window: Select "Refresh view (set positions as 'stored')".

  • Redraw the view (zoom out):Select "Redraw graph window (more refreshing)".

  • Update model:Select "Update model and redraw (total refreshing)".

  • Enable rotation:Select "Rest (enable) rotation".

  • Disable rotation:Select "Disable rotation".

  • Zoom in:Select "Zoom in" from main menu, or hit <F1> in canvas.

  • Zoom out:Select "Zoom out" from main menu, or hit <F2> in canvas.

  • Export current arguments:Select "Assign 'Args' in .GlobalEnv".

  • Export the model lattice:Select "Assign 'frameModels' in .GlobalEnv".

  • Export the graph lattice:Select "Assign 'frameViews' in .GlobalEnv".

  • Export the graph window:Select "Assign 'graphWindow' in .GlobalEnv".

  • Export the object:Select "Assign 'object' in .GlobalEnv".

Rotation:

  • Enable rotation:Select "Enable (reset) transformation" from the main menu "Graph".

  • Rotate the graph:Middle click the canvas, and drag.

  • Disable rotation:Select "Disable transformation" from the main menu "Graph".

  • Export transformation:Export the projection matrix - Select "Assign 'transformation' in .GlobalEnv" from the main menu "Graph".

Acknowledgments

Many thanks to the gR-group for useful discussions, especially to Claus Dethlefsen for testing early versions of this package on DEAL.

Note

Vertices, edges, blocks, block edges, factors, and factor edges are objects of the following classes: dg.Vertex, dg.Edge, and dg.Block contains dg.Node, dg.FactorVertex contains dg.Vertex, and dg.VertexEdge, dg.BlockEdge, dg.FactorEdge contains dg.Edge.

For lists of vertices, edges, blocks, block edges, factors, and factor edges the methods Names, Names<-, Colors, Colors<-, Labels, Labels<-, LabelPositions, LabelPositions<-, Positions, Positions<-, Strata, Strata<-, Indices, NodeAncestors, NodeAncestors<-, NodeDescendants, and NodeDescendants<- are available.

The model object of the call of dynamicGraphMain should have the methods modifyModel, testEdge, graphEdges, and setGraphEdges. When the graph is modified, by adding or dropping vertices or edge, the method modifyModel is called on the argument object of dynamicGraphMain. If an object is returned in the list of the returned value from modifyModel then object in dynamicGraphMain is replaced by this object, and the object is also assigned in the top level environment, if objectName was given to dynamicGraphMain.

The method testEdge of object should return an object with the methods label and width for labeling edges, see dg.Test-class.

The methods graphEdges and setGraphEdges are used to communicate the graph components between several views of the same model. The method graphEdges of the model object is for returning an object of class dg.graphedges-class to draw in the view, depending on the viewType. The method setGraphEdges of the model object is called on the model object when the model is modified.

Author(s)

Jens Henrik Badsberg

References

CoCo, with a guide at http://www.jstatsoft.org/v06/i04/, has an interface to dynamicGraph.

See Also

See also DynamicGraph and all the other functions of this package.

An example has been divided on the following 4 manual pages: dg.Model-class and dg.Test-class gives an example of a model object with test object. The pages of dg.graphedges-class show how the user can add menu items with actions that redraws the graph after modification of edges. Finally, validVertexClasses show how to create a new vertex class with a new symbol for drawing the vertex and an item added to the pop up menu of the new vertex class. The demo demo(Circle.newClass) of dynamicGraph will do this example collected from these 4 pages.

Examples

require(tcltk)
require(dynamicGraph)

V.Names <- paste(c("Sex", "Age", "Eye", "FEV", "Hair", "Shosize"),
                 1:6, sep ="/")

V.Types <- c("Discrete", "Ordinal", "Discrete",
             "Continuous", "Discrete", "Continuous")

Vertices <- returnVertexList(V.Names, types = V.Types, color = "red")

From <- c(1, 2, 3, 4, 5, 6)
To   <- c(2, 3, 4, 5, 6, 1)

EdgeList <- vector("list", length(To))
for (j in seq(along = To)) EdgeList[[j]] <- c(From[j], To[j])
Edges <- returnEdgeList(EdgeList, Vertices, color = "black")

# Z <- dynamicGraphMain(Vertices, edgeList = Edges, control = dg.control(w = 4))

graph <- new("dg.graph", vertexList = Vertices, edgeList = Edges)
W <- dg(graph, control = dg.control(w = 4))

dynamicGraph

dynamicGraph

v0.2.2.6
GPL (>= 2)
Authors
Jens Henrik Badsberg <coco@badsberg.eu>
Initial release
2010/01/30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.