# Global quasi-potential visualization

## Example 1 from Moore et al. (2016)

### Visualizing local quasi-potential surfaces

Users can visualize the global quasi-potential surface right away, but we like to build in a little bit of anticipation and have users think about the local surfaces and what they expect to see in a global quasi-potential surface.

First, let's view the local quasi-potential surfaces with `QPContour`.

```    QPContour(surface = eq1.local, dens = c(1000, 1000), x.bound = bounds.x, y.bound = bounds.y)
QPContour(surface = eq2.local, dens = c(1000, 1000), x.bound = bounds.x, y.bound = bounds.y)
```

Notice that plotting contours is not very fast. We have an argument, `dens`, that, when it's small, allows for faster plotting times. This argument simply subsamples the surface.

Next, looking at the stable node's surface (`eqs[3,]`), you'll notice that there's not much resolution, and it looks like a large, flat basin. Well, that's not the case. The stable equilibrium is there, but it's a shallow depression that's too shallow to be captured by the color scheme and contour lines. To see the depression, you could normally add more colors (`QPContour`) or add the number of contour lines, but that can be insufficient in many ways. What we did to overcome this is create an argument within `QPContour` that changes the density of contour lines. Specifically, the argument `c.parm` focuses the concentration of contour lines at that bottom of the basin, as the value increases from one. Try, for example, the above with `c.parm = 2` or `c.parm = 5`:

```    QPContour(surface = eq2.local, dens = c(1000, 1000), x.bound = bounds.x, y.bound = bounds.y, c.parm = 5)
```

This argument will come in handy, since the quasi-potential surfaces tend to span a large range, and we're often interested in the contours at the bottom of the basins.

### Visualizing the global quasi-potential surface

To visualize the global quasi-potential, one can simply take the global quasi-potential matrix from QPGlobal and use it to create a contour plot using `QPContour`.

```    QPContour(surface = ex1.global, dens = c(1000, 1000), x.bound = bounds.x, y.bound = bounds.y)
```

That's it---you've created the global quasi-potential!

### Alternative means of visualizing the quasi-potential

There are many different ways of visualizing the 3-dimensional data like the quasi-potential surfaces.

Probably most useful, we suggest `persp3d` in package `rgl`. This allows users to interact with the surface in 3 dimensions and gain a further understanding of the shape of the surface.

```    library("rgl")
persp3d(x = ex1.global, col = "#FF5500", xlab = "X", ylab = "Y", zlab = intToUtf8(0x03A6), xlim = c(0.05, 0.3), ylim = c(0.1, 0.3), zlim = c(0, 0.01))
```

Second, `image`, `contour`, and `filled.contour` are all `graphics` packages that work well with 3-dimensional data like the quasi-potential surfaces. For example:

```    image(x = ex1.global)
contour(x = ex1.global)
filled.contour(x = ex1.global)
```

Lastly, Karline Soetaert has written a package `plot3D` that has several other ways of visualizing the 3-dimensional data like the quasi-potential surfaces. For example:

```    persp3D(z = ex1.global, contour = F)
```

bmarkslash7/QPot documentation built on Jan. 11, 2020, 11:11 a.m.