Learn R Programming

dynamicGraph (version 0.1.6.6)

dynamicGraphMain: Dynamic Graph

Description

Interactive plot for manipulating graphs.

Usage

dynamicGraphMain(vertexList, visibleVertices = 1:length(vertexList),
                 edgeList = NULL, blockList = NULL, blockEdgeList = NULL,
                 blockTree = NULL, oriented = FALSE,
                 factorVertexList = NULL, factorEdgeList = NULL, 
                 extraList = NULL,
                 object = NULL, objectName = "", 
                 vertexClasses = validVertexClasses(),
                 title = "dynamicGraph", transformation = NULL, 
                 width = 400, height = 400, w = 6, 
                 vertexColor = "blue", extraVertexColor = "black", 
                 edgeColor = "blue",
                 factorVertexColor = "green", factorEdgeColor = "green",
                 blockEdgeColor = "default", blockColors = NULL,
                 background = "white", closeenough = 2,
                 drawBlockFrame = TRUE, drawBlockBackground = TRUE,
                 UserMenus = NULL, 
                 hasMethods = TRUE, enterLeaveUpdate = TRUE,
                 namesOnEdges = TRUE, updateEdgeLabels = TRUE,
                 debug.strata = FALSE, debug.edges = FALSE,
                 debug.position = FALSE, debug.update = FALSE, 
                 returnLink = FALSE, returnNull = FALSE, ...)

Arguments

vertexList
List of vertices (each of class containing the class VertexProto) created by returnVertexList or exported from dy
visibleVertices
Numeric vector of the indices of the vertices of vertexList to plot.
edgeList
List of edges (of class containing EdgeProto) created by returnEdgeList or exported from dynamicGraphMain.
blockList
List of blocks (each of class BlockProto) created by setBlocks or exported from dynamicGraphMain. If the
blockEdgeList
List of blockedges (of class containing the class BlockEdgeProto) created by returnBlockEdgeList or exported from
blockTree
Structure with blocks (of class BlockProto) created by setTreeBlocks or exported from dynamicGraphMain.
oriented
Logical. If TRUE then edges are oriented, also when blocks are missing.
factorVertexList
List of secondary vertices, called factor vertices, for, e.g., the generators of the model, (each of class containing FactorVertexProto) created by returnFacto
factorEdgeList
List of bipartite graph edges, called factor edges, (each of class containing FactorEdgeProto) created by returnFactorEdgeList or exported from
extraList
List of vertices (of class containing the class VertexProto) created by returnVertexList or exported from dynamicGraphM
object
NULL, or object with the methods modifyModel and testEdge - for respectively updating the object when the graph is updated, and for comp
objectName
If set to a text string then the object is assigned with this name in .Global.Env when the object is updated.
vertexClasses
Returned value from validVertexClasses, or extension of this matrix. Used when creating new vertices in dynamicGraphMain.
title
Text string with the title set on the graph window.
transformation
NULL, or rotation matrix for projecting the positions of the vertices, blocks, etc. onto the canvas.
width
Integer with the width of the plot canvas.
height
Integer with the height of the plot canvas.
w
The radius of the vertices. Send as argument to the draw method for vertices, and edges are shortened by the quantity in each end.
vertexColor
Single text string. Colors of new vertices created in dynamicGraphMain (by newVertex). The colors of the vertices
extraVertexColor
Single text string. As vertexColor, but for the vertices of extraList.
edgeColor
Single text string. edgeColor is similar to vertexColor.
factorVertexColor
Single text string. factorVertexColor is similar to vertexColor. If factorVertexColor is "default" then the color of a factor vertex will depend on the type of the generator o
factorEdgeColor
Single text string. factorEdgeColor is similar to edgeColor.
blockEdgeColor
"default", or list with two text strings for colors. blockEdgeColor is similar to edgeColor. The two colors are used for respectively edges between two blocks and for edges between blocks and vert
blockColors
List of colors of blocks. Similar to vertexColor: Only used when creating new blocks, else the colors set in blockList and blockTree are used.
background
The color of the canvas of the graph window, default: "white".
closeenough
Parameter for whether the mouse is close enough when clicking an object of the graph window, see tkcanvas.
drawBlockFrame
Logical. If TRUE then frames are drawn around blocks.
drawBlockBackground
Logical. If TRUE then a block canvas is drawn, with color set by blockColors.
UserMenus
List with user defined menu items for main menu and pop up menus. See redrawGraphWindow for an example of a user specified menu.
hasMethods
Logical. If TRUE then the object should have the methods modifyModel and testEdge. (I do not know why the R-funct
enterLeaveUpdate
Logical. If FALSE then the graph window is not redrawn when the mouse enters and leaves the graph window.
namesOnEdges
Logical. If FALSE then the names of the vertices are not set on the edge as label.
updateEdgeLabels
Logical. If FALSE then the edge labels are not cleared when the model is updated.
debug.strata
Logical for tracing strata of vertices (also in plot).
debug.edges
Logical for tracing edges (also by labels in plot).
debug.position
Logical for tracing positions of vertices.
debug.update
Logical for tracing redraw of graph window.
returnLink
Logical, if returnLink is TRUE then a reference to the dynamic graph window is returned, else an object of class GraphLatticeProto-class
returnNull
Logical, if returnNull is TRUE then NULL is returned.
...
Additional arguments.

Value

  • If returnLink is TRUE then a reference (an object of class "list") to the dynamic graph window is returned, else an object of class GraphLatticeProto-class is returned (if not returnNull is TRUE)

    The function redrawGraphWindow of the returned reference is used to draw other graphs in the graph window or to create slave graphs windows, see addGraph. The object of class GraphLatticeProto will beside the list of canvases of the graph window and slave windows, also hold lists of vertices and blocks (block trees).

  • ...@graphsSlot 'graphs': List of class CanvasProto. Might, beside slots for accessing the graph window, also hold slots for edges, factors, factor edges, block edges, etc.
  • ...@graphs[[i]]@topSlot 'top' of each object in the list of the 'graphs' slot of the returned object: The 'top' of the canvas of the i-the graph window.

All object in the graph window:

  • Left click, hold and drag:
{The object will move.} Left click:{Action to the object: Vertices and blocks will highlight, at vertices and blocks edges are added after highlighting, at edges the edge will be deleted, 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 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.} 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.}

itemize

  • Export the block list:

code

object

item

  • Display, add, a vertex:
  • Display, add, a vertex:
  • Export the vertex list:
  • Export the labels:
  • Export the edge list:
  • Export the block tree:
  • Export the block edges:

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

Right click the edge to get the pop up menu of the edge:
  • 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 - 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.}

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.} 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.}

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 FactorVertices in .GlobalEnv". } Export the factor edges:{Select "Assign FactorEdges 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 graph:

  • Create a slave window:
{Select "Copy: Make slave window".} Redraw (zoom out):{From the lists of objects - Select "Redraw the graph window".} Update:{Faster fix of "corrupted" window: Select "Update the graph window".} Export the linkGraphLattice :{Select "Assign linkGraphLattice in .GlobalEnv".} Export the graph lattice :{Select "Assign Graph-lattice in .GlobalEnv".} Export the graph window:{Select "Assign Graph-window 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.

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.

References

CoCo, avaliable form http://www.math.auc.dk/gr/material/CoCo and http://www.jbs.agrsci.dk/ Biometry/Software-Datasets/CoCo/CoCo.1.6/ 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: newDefaultModelObject and newDefaultTestObject gives an example of a model object with test object. The pages of redrawGraphWindow 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 files ".../dynamicGraph/Tests/Circle.newClass.R" of the example catalog of dynamicGraph will do this example collected from these 4 pages.

Examples

Run this code
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, w = 4)

Run the code above in your browser using DataLab