Learn R Programming

ggpmisc (version 0.2.17)

stat_quadrat_counts: Count the number of observations in each quadrat of a plot.

Description

stat_quadrat_counts counts the number of observations in each quadrat of a plot panel. By default it adds a text label to the far corner of each quadrat. It can also be used to obtain the total number of observations in each of two pairs of quadrats or in the whole panel. Grouping is ignored, so en every case a single count is computed for each quadrat in a plot panel.

Usage

stat_quadrat_counts(mapping = NULL, data = NULL, geom = "text",
  position = "identity", quadrats = NULL, pool.along = "none",
  origin.x = 0, origin.y = 0, labels.range.x = NULL,
  labels.range.y = NULL, na.rm = FALSE, show.legend = FALSE,
  inherit.aes = TRUE, ...)

Arguments

mapping

The aesthetic mapping, usually constructed with aes or aes_string. Only needs to be set at the layer level if you are overriding the plot defaults.

data

A layer specific dataset - only needed if you want to override the plot defaults.

geom

The geometric object to use display the data

position

The position adjustment to use for overlapping points on this layer

quadrats

integer vector indicating which quadrats are of interest, with a OL indicating the whole plot.

pool.along

character, one of "none", "x" or "y", indicating which quadrats to pool to calculate counts by pair of quadrats.

origin.x, origin.y

numeric the coordinates of the origin of the quadrats.

labels.range.x, labels.range.y

numeric Coordinates (in data units) to be used for absolute positioning of the labels.

na.rm

a logical indicating whether NA values should be stripped before the computation proceeds.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and should not inherit behaviour from the default plot specification, e.g. borders.

...

other arguments passed on to layer. This can include aesthetics whose values you want to set, not map. See layer for more details.

Computed variables

Data frame with one to four rows, one for each quadrat for which observations are present in data.

quadrat

integer, one of 0:4

x

extreme x value in the quadrat

y

extreme y value in the quadrat

count

number of ovserbations

Details

This stat can be used to automatically count observations in each of the four quadrats of a plot, and by default add these counts as text labels.

Examples

Run this code
# NOT RUN {
library(ggplot2)
# generate artificial data
set.seed(4321)
x <- 1:100
y <- rnorm(length(x), mean = 10)
my.data <- data.frame(x, y)

ggplot(my.data, aes(x, y)) +
  geom_point() +
  stat_quadrat_counts()

ggplot(my.data, aes(x - 50, y - 10)) +
  geom_hline(yintercept = 0, colour = "blue") +
  geom_vline(xintercept = 0, colour = "blue") +
  geom_point() +
  stat_quadrat_counts(colour = "blue")

ggplot(my.data, aes(x - 50, y - 10)) +
  geom_hline(yintercept = 0, colour = "blue") +
  geom_point() +
  stat_quadrat_counts(colour = "blue", pool.along = "x")

ggplot(my.data, aes(x - 50, y - 10)) +
  geom_vline(xintercept = 0, colour = "blue") +
  geom_point() +
  stat_quadrat_counts(colour = "blue", pool.along = "y")

ggplot(my.data, aes(x - 50, y - 10)) +
  geom_point() +
  stat_quadrat_counts(quadrats = 0)

# }

Run the code above in your browser using DataLab