---
title: "Plotting options"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Plotting options}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = FALSE
)
```

## Loading dataset and libraries

```{r setup}
library(flexFitR)
library(dplyr)
library(kableExtra)
library(ggpubr)
library(purrr)
data(dt_potato)
head(dt_potato) |> kable()
```

## Modeling

```{r}
plots <- 2:7
mod <- dt_potato |>
  modeler(
    x = DAP,
    y = Canopy,
    grp = Plot,
    fn = "fn_logistic",
    parameters = c(a = 4, t0 = 40, k = 100),
    subset = plots
  )
```


## Plotting predictions and derivatives

```{r,  fig.width= 8, fig.height=5, fig.alt="plot derivatives"}
# Raw data with fitted curves
plot(mod, type = 1, color = "blue", id = plots, title = "Fitted curves")
```

```{r,  fig.width= 8, fig.height=4, fig.alt="plot coef"}
# Model coefficients
plot(mod, type = 2, color = "blue", id = plots, label_size = 10)
```

```{r}
# Fitted curves only
c <- plot(mod, type = 3, color = "blue", id = plots, title = "Fitted curves")
```

```{r}
# Fitted curves with confidence intervals
d <- plot(mod, type = 4, n_points = 200, title = "Fitted curve (uid = 2)")
```

```{r}
# First derivative with confidence intervals
e <- plot(mod, type = 5, n_points = 200, title = "1st Derivative (uid = 2)")
```

```{r,  fig.width= 10, fig.height=7, fig.alt="plot derivatives"}
# Second derivative with confidence intervals
f <- plot(mod, type = 6, n_points = 200, title = "2nd Derivative (uid = 2)")
ggarrange(c, d, e, f)
```
