applySpline {seqsetvis} | R Documentation

## applies a spline smoothing to a tidy data.table containing x and y values.

### Description

`applySpline` Is intended for two-dimensional tidy data.tables, as retured by `ssvFetchBigwig`

### Usage

    applySpline(dt, n, x_ = "x", y_ = "y", by_ = "",
      splineFun = stats::spline)

### Arguments

`dt` | a tidy data.table containing two-dimensional data
`n` | the number of interpolation points to use per input point, see `?spline`. n must be > 1.
`x_` | the variable name of the x-values
`y_` | the variable name of the y-values
`by_` | optionally, any variables that provide grouping to the data. default is none. see details.
`splineFun` | a function that accepts x, y, and n as arguments and returns a list of length 2 with named elements x and y. `stats::spline` by default. see `stats::spline` for details.

### Details

by_ is quite powerful. If `by_ = c('gene_id', 'sample_id')`, splines will be calculated individually for each gene in each sample. alternatively if `by_ = c('gene_id')`

### Value

a newly derived data.table that is `n` times longer than original.

### See Also

`ssvFetchBigwig`

### Examples

    #data may be blockier than we'd like
    ggplot(CTCF_in_10a_profiles_dt[, list(y = mean(y)), by = list(sample, x)]) +
        geom_line(aes(x = x, y = y, color = sample))

    #can be smoothed by applying a spline  (think twice about doing so,
    #it may look prettier but may also be deceptive or misleading)

    splined_smooth = applySpline(CTCF_in_10a_profiles_dt, n = 10,
        y_ = 'y', by_ = c('id', 'sample'))
    ggplot(splined_smooth[, list(y = mean(y)), by = list(sample, x)]) +
        geom_line(aes(x = x, y = y, color = sample))

[Package seqsetvis version 1.6.0 Index]