plot a Spatial Point Pattern

Plot a two-dimensional spatial point pattern

hplot, spatial
## S3 method for class 'ppp':
plot(x, main, \dots, clipwin=NULL,
                    chars=NULL, cols=NULL,
                    use.marks=TRUE, which.marks=NULL,
                    add=FALSE, type=c("p","n"),
                    leg.side=c("left", "bottom", "top", "right"),
                    symap=NULL, maxsize=NULL, markscale=NULL, zap=0.01,
                    show.window=show.all, show.all=!add, do.plot=TRUE,
The spatial point pattern to be plotted. An object of class "ppp", or data which can be converted into this format by as.ppp().
text to be displayed as a title above the plot.
extra arguments that will be passed to the plotting functions plot.default, points and/or symbols
Optional. A window (object of class "owin"). Only this subset of the image will be displayed.
plotting character(s) used to plot points.
the colour(s) used to plot points.
logical flag; if TRUE, plot points using a different plotting symbol for each mark; if FALSE, only the locations of the points will be plotted, using points().
Index determining which column of marks to use, if the marks of x are a data frame. A character or integer vector identifying one or more columns of marks. If add=FALSE then the default is to plot all columns
logical flag; if TRUE, just the points are plotted, over the existing plot. A new plot is not created, and the window is not plotted.
Type of plot: either "p" or "n". If type="p" (the default), both the points and the observation window are plotted. If type="n", only the window is plotted.
Logical value indicating whether to add a legend showing the mapping between mark values and graphical symbols (for a marked point pattern).
Position of legend relative to main plot.
Additional arguments passed to plot.symbolmap to control the legend.
Optional. The graphical symbol map to be applied to the marks. An object of class "symbolmap"; see symbolmap.
Maximum size of the circles/squares plotted when x is a marked point pattern with numerical marks. Incompatible with markscale. Ignored if symap is given.
physical scale factor determining the sizes of the circles/squares plotted when x is a marked point pattern with numerical marks. Incompatible with maxsize. Ignored if symap is given.
Fraction between 0 and 1. When x is a marked point pattern with numerical marks, zap is the smallest mark value (expressed as a fraction of the maximum possible mark) that will be plotted. Any points which ha
Logical value indicating whether to plot the observation window of x.
Logical value indicating whether to plot everything including the main title and the observation window of x.
Logical value determining whether to actually perform the plotting.
Logical value giving permission to display multiple plots.

This is the plot method for point pattern datasets (of class "ppp", see ppp.object).

First the observation window x$window is plotted (if show.window=TRUE). Then the points themselves are plotted, in a fashion that depends on their marks, as follows. [object Object],[object Object],[object Object],[object Object]

If there are several columns of marks, and if which.marks is missing or NULL, then

  • ifadd=FALSEandmultiplot=TRUEthe default is to plot all columns of marks, in a series of separate plots, placed side-by-side. The plotting is coordinated byplot.listof, which callsplot.pppto make each of the individual plots.
  • Otherwise, only one column of marks can be plotted, and the default iswhich.marks=1indicating the first column of marks.

Plotting of the window as.owin(x) is performed by plot.owin. This plot may be modified through the ... arguments. In particular the extra argument border determines the colour of the window, if the window is not a binary mask.

Plotting of the points themselves is performed by the function points, except for the case of continuous marks, where it is performed by symbols. Their plotting behaviour may be modified through the ... arguments.

The argument chars determines the plotting character or characters used to display the points (in all cases except for the case of continuous marks). For an unmarked point pattern, this should be a single integer or character determining a plotting character (see par("pch")). For a multitype point pattern, chars should be a vector of integers or characters, of the same length as levels(x$marks), and then the $i$th level or type will be plotted using character chars[i].

If chars is absent, but there is an extra argument pch, then this will determine the plotting character for all points. The argument cols determines the colour or colours used to display the points. For an unmarked point pattern, or a marked point pattern with continuous marks, this should be a character string determining a colour. For a multitype point pattern, cols should be a character vector, of the same length as levels(x$marks). The $i$th level or type will be plotted using colour cols[i].

If cols is absent, the colour used to plot all the points may be determined by the extra argument fg (for multitype point patterns) or the extra argument col (for all other cases). Note that col will also reset the colour of the window.

The arguments maxsize and markscale incompatible. They control the physical size of the circles and squares which represent the marks in a point pattern with continuous marks. The size of a circle is defined as its diameter; the size of a square is its side length. If markscale is given, then a mark value of m is plotted as a circle of diameter m * markscale (if m is positive) or a square of side abs(m) * markscale (if m is negative). If maxsize is given, then the largest mark in absolute value, mmax=max(abs(x$marks)), will be scaled to have physical size maxsize.

The user can set the default values of these plotting parameters using spatstat.options("par.points"). To zoom in (to view only a subset of the point pattern at higher magnification), use the graphical arguments xlim and ylim to specify the rectangular field of view.

The value returned by this plot function is an object of class "symbolmap" representing the mapping from mark values to graphical symbols. See symbolmap. It can be used to make a suitable legend, or to ensure that two plots use the same graphics map.


  • (Invisible) object of class "symbolmap" giving the correspondence between mark values and plotting characters.

Removing White Space Around The Plot

A frequently-asked question is: How do I remove the white space around the plot? Currently plot.ppp uses the base graphics system of R, so the space around the plot is controlled by parameters to par. To reduce the white space, change the parameter mar. Typically, par(mar=rep(0.5, 4)) is adequate, if there are no annotations or titles outside the window.

See Also

iplot, ppp.object, plot, par, points, plot.owin, symbols

  • plot.ppp

   plot(cells, pch=16)

   # make the plotting symbols larger (for publication at reduced scale)
   plot(cells, cex=2)

   # set it in spatstat.options
   oldopt <- spatstat.options(par.points=list(cex=2))

   # multitype 

   # marked by a real number

   # just plot the points
   plot(longleaf, use.marks=FALSE)
   plot(unmark(longleaf)) # equivalent

   # point pattern with multiple marks
   plot(finpines, which.marks="height")

   # controlling COLOURS of points
   plot(cells, cols="blue")
   plot(lansing, cols=c("black", "yellow", "green", 
   plot(longleaf, fg="blue")

   # make window purple
   plot(lansing, border="purple")
   # make everything purple
   plot(lansing, border="purple", cols="purple", col.main="purple",
   # controlling PLOT CHARACTERS
   plot(lansing, chars = 11:16)
   plot(lansing, chars = c("o","h","m",".","o","o"))

   # controlling MARK SCALE
   plot(longleaf, markscale=0.1)

   # draw circles of diameter equal to nearest neighbour distance
   plot(cells %mark% nndist(cells), markscale=1, legend=FALSE)

   # inspecting the symbol map
   v <- plot(amacrine)

   ## re-using the same mark scale
   a <- plot(longleaf)
   juveniles <- longleaf[marks(longleaf) < 30]
   plot(juveniles, symap=a)

   ## numerical marks mapped to symbols of fixed size with variable colour
   ra <- range(marks(longleaf))
   colmap <- colourmap(terrain.colors(20), range=ra)
   ## filled plot characters are the codes 21-25
   ## fill colour is indicated by 'bg'
   sy <- symbolmap(pch=21, bg=colmap, range=ra)
   plot(longleaf, symap=sy)
Documentation reproduced from package spatstat, version 1.37-0, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.