Count points in a scatter plot
WhereXY.Rd
count the number of points that fall into various sized subparts of a scatter plot. The graphing region can be split into cells based on a uniform or normal marginal distribution separately for the x and y variables.
Usage
WhereXY(x, y = NULL, grid = c(4, 4), xDist = "uniform",
yDist = xDist, addmargins=TRUE)
Arguments
- x,y
vectors of x coordinates. If y is not specified, the function expects x to be a two-column matrix with x and y values in columns 1 and 2 respectively.
- grid
pair of values to specify the way the graph is to be split into parts. Specify x and then y.
- xDist,yDist
the distribution the variables might be expected to follow. The default is to consider uniformly distributed but any alternative text will lead to an assumption of both margins being normally distributed.
- addmargins
logical: should sums be added to both rows and columns.
Value
A text description of the number of points in each subregion of the scatter plot. The table of counts can then be compared to the expected number of points in each subregion.
Examples
x=rnorm(50)
y=rnorm(50)
WhereXY(x,y)
#> 1 2 3 4 Sum
#> 4 0 1 1 0 2
#> 3 3 2 4 0 9
#> 2 2 10 7 3 22
#> 1 3 4 7 3 17
#> Sum 8 17 19 6 50
WhereXY(x,y, c(3,4))
#> 1 2 3 Sum
#> 4 0 2 0 2
#> 3 3 4 2 9
#> 2 3 16 3 22
#> 1 4 9 4 17
#> Sum 10 31 9 50
WhereXY(x,y, xDist="other")
#> 1 2 3 4 Sum
#> 4 3 3 1 4 11
#> 3 3 5 1 1 10
#> 2 1 3 7 6 17
#> 1 3 2 4 3 12
#> Sum 10 13 13 14 50