Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 16: Figure expected to go in margin overlies main-column text #33

Open
homerhanumat opened this issue Jan 13, 2025 · 0 comments
Open

Comments

@homerhanumat
Copy link

homerhanumat commented Jan 13, 2025

Note: I suggest a fix for the issue at the end.

The issue is with this figure:

```{r warning = FALSE, echo=FALSE}
#| label: fig-narrowing-likelihood
#| fig-cap: "The likelihood calculated from multiple observations. The thin red line is drawn at 1/7 the height of the peak."
#| fig-subcap:
#| - First 10 observations
#| - After 30 observations
#| - After 100 observations
#| layout-ncol: 1
#| column: margin
LL <- function(n, rate) {
    sofar = 0 * rate
    for (k in 1:n) {
      sofar <- sofar + log(dexp(The_observations$interval[k], rate))
    }
    exp(sofar)
}
# Find the maximum value
one <- max(LL(10, seq(0, .03, length=200)))
five <- max(LL(30, seq(0, .03, length=200)))
ten <- max(LL(100, seq(0, .03, length=200)))

slice_plot(LL(10, rate)/one ~ rate, rate = domain(0:0.03), npts = 500, color = "black") |>
  gf_hline(yintercept = ~ 1/7, color="red", alpha=0.5) |>
  gf_segment(0.143 + 0.143 ~ 0.006 + 0.0205, size=3, color="red")
slice_plot(LL(30, rate)/five ~ rate, rate = domain(0:0.03), npts = 500, color = "blue") |>
  gf_hline(yintercept = ~ 1/7, color="red", alpha=0.5) |>
  gf_segment(0.143 + 0.143 ~ 0.0084 + 0.0171, size=3, color="red")
slice_plot(LL(100, rate)/ten ~ rate, rate = domain(0:0.03), npts = 500, color = "magenta") |>
  gf_hline(yintercept = ~ 1/7, color="red", alpha = 0.5) |>
  gf_segment(0.143 + 0.143 ~ 0.0109 + 0.0161, size=3, color="red")

```

The figure does not go in the margin, but instead appears in the main column, lying on top of your narrative, and most of the first two exercises.

I reproduced the issue in a test document and found that changing layout-ncol: 1 to layout-row: 3 made it work correctly.

Update: I filed an issue here and got some helpful advice that as far as I know is not in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant