Skip to contents

Given a Grid1d class object and a matrix or dataframe of points, it returns a dataframe with original points and a supplementary column which groups the y points that fall in the same vertical strip.

Usage

getBoxplot(grid, points)

Arguments

grid

Grid1d object, made with makeGrid1d function

points

2d matrix or dataframe of points

Value

A dataframe with three columns: xbp (x relative to boxplot), x and y (original points)

Examples

# 1. Generate random points on a plane
df_points <- data.frame(
  x = c(rnorm(n = 50000, mean = -2), rnorm(n = 50000, mean = 2)),
  y = c(rnorm(n = 50000, mean = 1), rnorm(n = 50000, mean = -1))
)

# 2. Define a grid that contains all the points generated along x
stripes <- makeGrid1d(
  xmin = floor(min(df_points$x)), xmax = ceiling(max(df_points$x)), xcell = 50
)

# 3. Obtain boxplot dataframe
df_boxplot <- getBoxplot(stripes, df_points)

head(df_boxplot)
#>     xbp          x          y
#> 1  -3.5 -3.4000435 -0.3366065
#> 2 -1.82 -1.7446829  1.0899147
#> 3 -4.34 -4.4372636  1.3799959
#> 4  -2.1 -2.0055713  0.9439657
#> 5 -1.26 -1.3784473  1.7008630
#> 6 -0.98 -0.8515884  1.2532184