Learn R Programming

RnavGraph (version 0.1.8)

ng_2d_myplot: Visualization instruction for 2d scatterplots on a user defined display

Description

Visualization instruction for a navGraph session that link the nodes of a navigation graph to 2d scatterplots and the edges to a 3d rigid rotation or a 4d transition.

navGraph will call at any bullet state change a function the user defines in the global environment.

The executed function should contain plot instruction and have any subset of these arguments

argument
description
x
x-coordinate
y
y-coordinate
group
group slot from NG_data object
labels
labels slot from NG_data object
order
order of points. In 3d rigid rotation, the order increases with the distance of a the point from the viewer.
from
node name the bullet moves from
to
node name the bullet moves to
percentage
in between percentage of bullet

Usage

ng_2d_myplot(data, graph, fnName, device = "base", scaled = TRUE)

Arguments

data
NG_data object.
graph
NG_graph object.
fnName
Character sting of the function name defined in the global environment .GlobalEnv. If a function with the name fnName.init also exists, it gets called to initialize the plots.
device
One of the following choices: "base", "grid", "ggplot2", "lattice" or "rgl".
scaled
Logical. If TRUE, scaled x and y coordinates get passed to the function fnName which lie within the rectangle defined by (-1,-1) and (1,1).

See Also

navGraph, ng_data, ng_graph, ng_get-methods, ng_set-methods, ng_2d

Examples

Run this code
library(grid)

## NG_data
ng.iris <- ng_data(name = "iris", data = iris[,1:4],
		shortnames = c('s.L', 's.W', 'p.L', 'p.W'),
		group = iris$Species,
		labels = substr(iris$Species,1,2))

## NG_graph
V <- shortnames(ng.iris)
G <- completegraph(V)
LG <- linegraph(G)
LGnot <- complement(LG)
ng.lg <- ng_graph(name = '3D Transition', graph = LG, layout = 'circle')
ng.lgnot <- ng_graph(name = '4D Transition', graph = LGnot, layout = 'circle')

## initialization plot
myPlot.init <- function(x,y,group,labels,order) {
	pushViewport(plotViewport(c(5,4,2,2)))
	pushViewport(dataViewport(c(-1,1),c(-1,1),name="plotRegion"))
	
	grid.points(x,y, name = "dataSymbols")
	grid.rect()
	grid.xaxis()
	grid.yaxis()
	grid.edit("dataSymbols", pch = 19)
	grid.edit("dataSymbols", gp = gpar(col = group))
}

## update plot
myPlot <- function(x,y,group,labels,order) {
  print(order)
	grid.edit("dataSymbols",
           x = unit(x,"native"),
           y = unit(y,"native"))
      }

## Visualization instruction
viz1 <- ng_2d_myplot(ng.iris,ng.lg,fnName = "myPlot",
           device = "grid", scaled=TRUE)

## navGraph session
nav <- navGraph(ng.iris,ng.lg, viz1)

Run the code above in your browser using DataLab