- To copy this instruction to R, highlight it (using the right key of your mouse), press 'Control+C (on your keyboard), switch to R's Windows graphical interface (assuming R is open), and paste it in (using the Control+V keys).
As you might expect, many of the functions that plot map-like outputs take the information in the form of matrix (tabular) variables - and many other calculations are more easily performed upon data encoded as 'rows' and 'columns'. The matrix function converts an ordinary vector-type variable to a matrix with the specified number of rows or columns.
To get R to display the contents of variable y, simply input the variable's name, y
- The image function simply displays the values in the matrix variable, y, as coloured (or shaded) rectangles. In this case the colours were chosen automatically, but can be specified using the col argument - as described in the ?image help page.
- The argument col=topo.colors(9) tells the contour function to select its colours from 9 colours of a palette called topo.colours. If you just want blue contours use col = 'blue', for black contours omit the col argument altogether. To add contour lines to an existing plot set the add argument of this function equal to TRUE (by including add = TRUE).
- Because of the legend running down the right of the filled contour plot it is incompatible with many other plot types - which makes more awkward to overplot. For a demonstration of some of R's graphics abilities, use demo(graphics)
- To shade the perspective graph using colours, rather than shades of grey, you need to provide the pers object with a color (or colours) to work from. For example, to use shades of green, insert col = 'green'.
Notice that, although you can specify a variety of lighting effects for perspective graphs, you cannot use the persp function to tint your perspective graph according to its height (like a 3 dimensional map).
The graphics package of R contains various functions enabling you to add information to an existing plot.
- For example, grid(10, 10) would add a grid pattern to this plot - diving it into 10 × 10 rectangles.
- The symbols function allows you to add simple symbols. For example symbols(runif(5), runif(5), circles=runif(5), add=TRUE) would add 5, randomly positioned circles, of random radius.
- Similarly text(.5, .5, label = 'location', col = 'red') would add the word location to the middle of the image.
- The arrows function allows you to add arrows between pairs of locations.