adj2HPD {HiveR}R Documentation

Process an Adjacency Graph into a HivePlotData Object

Description

This function will take an adjacency graph and convert it into a basic HivePlotData object. Further manipulation by mineHPD will almost certainly be required before the data can be plotted.

Usage

adj2HPD(M = NULL, axis.cols = NULL, type = "2D", desc = NULL, ...)

Arguments

M

A matrix with named dimensions. The names should be the node names. Should not be symmetric. If it is, only the lower triangle is used and a message is given.

axis.cols

A character vector giving the colors desired for the axes.

type

One of c("2D", "3D"). If 2D, a HivePlotData object suitable for use with plotHive will be created and the eventual hive plot will be static and 2D. If 3D, the HivePlotData object will be suitable for a 3D interactive plot using plot3dHive.

desc

Character. A description of the data set.

...

Other parameters to be passed downstream.

Details

This function produces a "bare bones" HivePlotData object. The names of the dimensions of M are used as the node names. All nodes are given size 1, an id number (1:number of nodes), are colored black and are assigned to axis 1. The edges are all gray, and the weight is M[i,j]. The user will likely have to manually make some changes to the resulting HivePlotData object before plotting. Alternatively, mineHPD may be able to extract some information buried in the data, but even then, the user will probably need to make some adjustments. See the examples.

Value

A HivePlotData object.

Author(s)

Bryan A. Hanson, DePauw University. hanson@depauw.edu Vesna Memisevic contributed a fix that limited this function to bipartite networks (changed in v. 0.2-12).

See Also

dot2HPD and adj2HPD

Examples


### Example 1: a bipartite network
### Note: this first example has questionable scientific value!
### The purpose is to show how to troubleshoot and
### manipulate a HivePlotData object.

if (require("bipartite")) {
  data(Safariland, package = "bipartite") # This is a bipartite network

  # You may wish to do ?Safariland or ?Safari for background

  hive1 <- adj2HPD(Safariland, desc = "Safariland data set from bipartite")
  sumHPD(hive1)

  # Note that all nodes are one axis with radius 1. Process further:

  hive2 <- mineHPD(hive1, option = "rad <- tot.edge.count")
  sumHPD(hive2)

  # All nodes still on 1 axis but degree has been used to set radius

  # Process further:

  hive3 <- mineHPD(hive2, option = "axis <- source.man.sink")
  sumHPD(hive3, chk.all = TRUE)

  # Note that mineHPD is generating some warnings, telling us
  # that the first 9 nodes were not assigned to an axis.  Direct
  # inspection of the data shows that these nodes are insects
  # that did not visit any of the flowers in this particular study.

  # Pretty up a few things, then plot:

  hive3$edges$weight <- sqrt(hive3$edges$weight) * 0.5
  hive3$nodes$size <- 0.5
  plotHive(hive3)

  # This is a one-sided hive plot of 2 axes, which results
  # from the curvature of the splines.  We can manually fix
 # this by reversing the ends of edges as follows:

  for (n in seq(1, length(hive3$edges$id1), by = 2)) {
    a <- hive3$edges$id1[n]
    b <- hive3$edges$id2[n]
    hive3$edges$id1[n] <- b
    hive3$edges$id2[n] <- a
  }

  plotHive(hive3)

  ### Example 2, a simple random adjacency matrix
  set.seed(31)
  nr <- 20
  nc <- 15
  M <- matrix(floor(runif(nc * nr, 0, 10)), ncol = nc)
  colnames(M) <- sample(c(letters, LETTERS), nc, replace = FALSE)
  rownames(M) <- sample(c(letters, LETTERS), nr, replace = FALSE)
  hive4 <- adj2HPD(M)
  sumHPD(hive4)
}


[Package HiveR version 0.4.0 Index]