Session Ready
Exercise

Mapping segregation

With a base map and some image and contour functions we can display both the probabilities and the significance tests over the area with more control than the plotmc() function.

The seg object is a list with several components. The X and Y coordinates of the grid are stored in the $gridx and $gridy elements. The probabilities of each class of data (violent or non-violent crime) are in a matrix element $p with a column for each class. The p-value of the significance test is in a similar matrix element called $stpvalue. Rearranging columns of these matrices into a grid of values can be done with R's matrix() function. From there you can construct list objects with a vector $x of X-coordinates, $y of Y-coordinates, and $z as the matrix. You can then feed this to image() or contour() for visualization.

This process may seem complex, but remember that with R you can always write functions to perform complex tasks and those you may repeat often. For example, to help with the mapping in this exercise you will create a function that builds a map from four different items.

The seg object from 1000 simulations is loaded, as well as the preston_crime points and the preston_osm map image.

Instructions 1/4
undefined XP
  • 1
  • 2
  • 3
  • 4

Inspect the segration object. - Use str() to see the structure of seg. - Set ncol as the length of one of the elements of seg.