spatial.plot {streamDAG}R Documentation

Spatial plot of an igraph object or stream shapefile

Description

Makes a spatial plot of a igraph object or stream shapefile, given nodal coordinates and node IDs.

Usage


spatial.plot(G, x, y, names = NULL, 
                         plot = TRUE,
                         col = "lightblue", 
                         cex.text = .4, cex = 1,
                         arrow.col = "lightblue", arrow.lwd = 1, 
                         plot.bg = "white", pch = 21, 
                         pt.bg = "orange", grid.lwd = 2, 
                         plot.dry = FALSE,
                         col.dry = gray(.7),
                         cex.dry = 1, pch.dry = 19, 
                         arrow.col.dry = gray(.7), arrow.lwd.dry = 1,
                         cnw = NULL, xlim = NULL, ylim = NULL, 
                         arrow.warn = TRUE, ...)


spatial.plot.sf(x, y, names, shapefile = NULL, cex = 1, arrow.col = "lightblue", 
                arrow.lwd = 1, pch = 21, pt.bg = "orange")

Arguments

G

Graph object, see graph_from_literal.

x

X-coordinates of nodes.

y

Y-coordinates of nodes.

names

Names of nodes, must use the same names as G and correspond to the order of coordinates in x and y.

plot

Logical. Create plot?

shapefile

Shapefile object brought in using library sf

col

point symbol color.

cex.text

Character expansion for node labels in plot; cex.text = 0 suppresses labels.

cex

Chahracter expnansion of point symbols.

arrow.col

Color of plot arrows.

arrow.lwd

Arrow line width.

plot.bg

Background color of plot.

pch

Plotting character.

pt.bg

Background color for plotting character.

grid.lwd

Grid line width; grid.lwd = 0 suppresses grid.

plot.dry

Logical. Should “dry” nodes, i.e., nodes in names (and x and y) that are not also in G be plotted?

col.dry

Color of “dry” nodes in plot.

cex.dry

Symbol sizer of “dry” nodes in plot.

pch.dry

Plotting character (symbol) of “dry” nodes in plot.

arrow.col.dry

Arrow color for "dry" arcs. Dry arrow rendering requires cnw designation (see Examples).

arrow.lwd.dry

Arrow line width for "dry" arcs. Dry arrow rendering requires cnw designation (see Examples).

cnw

Complete network spatial.plot object.

xlim

A numeric vector of length 2, giving the lower and upper y-axis limits.

ylim

A numeric vector of length 2, giving the lower and upper x-axis limits.

arrow.warn

Logical. The function arrows omits arrowheads (with a warning) for any arrow of length less than 1/1000 inch. To elimiate this warning (which may occur for nearby nodes) specify arrow.warn = FALSE.

...

Other arguments to plot

Details

The function spatial.plot makes a plot of a stream DAG, showing arc flow directions to and from spatial node locations. The function can also be used to identify node and arc arrow coordinates for plotting (see Examples). The function spatial.plot.sf can create a spatially explicit graph from a stream shapefile with the stream outlay under a ggplot framework (see Examples). The function spatial.plot can be used to distinguish dry and wet nodes and arcs) (see Examples).

Value

A plot and an invisible list containing the x and y coordinates of nodes: the objects $x and $y, respectively, and the x and y coordinates of start and end points of arc arrows:the objects $x0, $y0, $x1, and $y1, respectively.

Author(s)

Ken Aho

Examples

G <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, 
M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452,
M1452--+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, 
M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153,
M153 --+ M91 --+ OUT)

data(mur_coords)

x <- mur_coords[,2]
y <- mur_coords[,3]
names <- mur_coords[,1]
spatial.plot(G, x, y, names)

# using shapefiles


library(ggplot2); library(sf); library(ggrepel)
mur_sf <- st_read(system.file("shape/Murphy_Creek.shp", package="streamDAG"))
g1 <- spatial.plot.sf(x, y, names, shapefile = mur_sf)

# modify ggplot
g1 + theme_classic()



#-- Distinguishing wet and dry arcs and nodes --#

data(mur_node_pres_abs) # STIC H2O presence/absence
npa <- mur_node_pres_abs[650,][,-1] # STC data from 8/9/2019 22:30 
G1 <- delete.nodes.pa(G, npa) # delete nodes based STIC data

# Example 1 (only show wet nodes and arcs with associated wet nodes)
spatial.plot(G1, x, y, names)

# Example 2 (show wet nodes and arcs with associated wet nodes, and dry nodes)
spatial.plot(G1, x, y, names, plot.dry = TRUE)

# Example 3 (show wet nodes and arcs wet node arcs, and underlying network)
entire <- spatial.plot(G, x, y, names, plot = FALSE)
spatial.plot(G, x, y, names, plot.dry = TRUE, cnw = entire)


#-- Animation: drying of Johnson Draw drainage --#

jd_graph <- streamDAGs("jd_full")
data(AIMS.node.coords)
jd_coords <- AIMS.node.coords[AIMS.node.coords$site == "JD",]
jd_coords <- jd_coords[jd_coords$STIC_inferred_PA,] 
data(jd_node_pres_abs)

pb = txtProgressBar(min = 1, max = 250, initial = 1, style = 3) 
times <- round(seq(1,50322, length = 250),0)

for(i in 1:250){
  dev.flush()
  jd_sub <- delete.nodes.pa(jd_graph, 
                            jd_node_pres_abs[times[i],][-1],
                            na.response = "treat.as.1")
  spatial.plot(jd_sub, 
               x = jd_coords[,3], 
               y = jd_coords[,2], 
               names = jd_coords[,1], 
               ylim = c(43.122, 43.129), 
               xlim = c(-116.8, -116.775), 
               plot.dry = TRUE, main = jd_node_pres_abs[,1][times[i]], 
               xlab = "Longitude", ylab = "Latitude")
  dev.hold()
  Sys.sleep(.05)
  setTxtProgressBar(pb, i)
  }


[Package streamDAG version 1.5 Index]