View source: R/math-related-functions.R
fit_curve | R Documentation |
Fits a curve to a numeric vector.
fit_curve(input, fn, rev = FALSE, normalize = TRUE)
input |
Numeric vector. |
fn |
Character value. The function to call specified as a string.
Must be in output of |
rev |
If set to 1 or 'x' the fitted curve is returned reverted along the x-axis. If set to
2 or 'y' the fitted curve is returned reverted along the y-axis. (Depending on the curve 1 or
2 might not differ in the output. Compare |
normalize |
Logical. If set to TRUE numeric values will be scaled to values between one and zero. |
This function takes a numeric vector of length x and returns
a numeric vector of the same length. The values of the returned vector correspond to
the values needed to display or work with the pattern specified in fn
.
Numeric vector.
library(tidyverse)
library(confuns)
library(magrittr)
data.frame(variable = normalize(base::log(1:100))) %>%
dplyr::mutate(
curve = fit_curve(input = variable, fn = "sinus", normalize = TRUE),
residuals = (variable - curve) %>% normalize() ,
seq = row_number()) %>%
tidyr::pivot_longer(
cols = dplyr::all_of(x = c("curve", "residuals", "variable")),
names_to = "pattern",
values_to = "values") %>%
ggplot(mapping = aes(x = seq, y = values)) +
geom_line(mapping = aes(color = pattern))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.