View source: R/create_segments.R
create_segments | R Documentation |
Functions can be approximated by a sequence of piecewise-linear segments. This function generates the information needed for plotting those segments, as you might if the piecewise linear approximation were plotted on top of the slice_plot() of the function.
create_segments(ftilde, domain, h = NULL, nsegs = 20)
ftilde |
a tilde expression, as in |
domain |
specification of a domain, as in |
h |
an alternative to |
nsegs |
how many segments to divide the domain into |
a data frame (see examples)
## Not run: fun <- sin(x) ~ x dom <- bounds(x = c(-5,5)) segments <- create_segments(fun, domain=dom, nsegs=20) slice_plot(fun, dom) %>% # show the slope function as slopes gf_segment(y + yend ~ x + xend, data = segments, color=~slope) %>% gf_refine(scale_color_viridis_c()) slice_plot(fun, dom) %>% # piecewise linear approximations gf_segment(yf + yfend ~ x + xend, data = segments, color=~slope, size=2, alpha=0.5) %>% gf_refine(scale_color_viridis_c()) slice_plot(fun, dom) %>% # show the approximate slope function gf_line(slope ~ x , data = segments, color=~slope) %>% gf_refine(scale_color_viridis_c()) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.