1

First, I make two Waffleplots (I think I did it with ggplot)

(...)
waffle_school <- make_waffle(schoolsoort, StudentId)

(...)
waffle_bench <- make_waffle(schoolsoort, benchStudentId)
(...)

using some function:

make_waffle <- function(variableCol, uniqueIdentifiers, numberRowsWaffle = 5, deleteZeros=1) {
(...)  
 waffle <- waffle(categ_table, colors = Kleuren_schoolsoort[names(Kleuren_schoolsoort) %in% names(categ_table)], rows = numberRowsWaffle) + 
    theme(legend.position = "bottom") + colScale #+ guides(fill=guide_legend(ncol=4, byrow=TRUE)) 
  return(waffle)
}

Then I actually show the plots at some point in the text

{r Waffleplot-school, fig.height = 2.5, fig.margin=TRUE, fig.cap="\\textcolor{TIGcaptioncolor}{Leerlingen per schoolsoort 21/22 op jullie school}"}
  waffle_school

and

{r Waffleplot-landelijk, fig.height = 2.5, fig.margin=TRUE, fig.cap=cap1}
  waffle_bench
}

which I later want to refer to in my text, by saying: "In Figure \ref{fig:Waffleplot-school} you can see (..) and in Figure \ref{fig:Waffleplot-landelijk} you see (...)."

This leaves me with question marks in the actual reference in de pdf. By the way, I use pdflatex as a renderer.

Also, this is a part of the yaml header that my main Rmd file has, which I run from another R file.

---
output: 
  pdf_document:
    number_sections: true
    keep_tex: true
    fig_caption: yes
    latex_engine: pdflatex
    extra_dependencies: ["flafter"]

then, I call the Rmd file with the pictures and text (incl. references) in it, which has the following header:

---
title: "SchoolInBeeld"
author: "Marja"
date: "`r Sys.Date()`"
bookdown::pdf_document2
---

I have seen the notation \@ref{}, which yielded the exact reference latex call instead of the reference itself: "\ref{fig:Waffleplot-school}". Also, I have visited many questions on this, like

I feel like the output format is the problem though. Something like me trying to use bookdown things but cannot figure out how to call that package.

FYI, I am fluent in Latex, but relatively new to R.

  • By the way, I also used lualatex as a Latex engine, but it messed up my whole 'look and feel' and also did not solve the problem; still two questionmarks. – Marja van der Wind Jan 18 '23 at 14:00
  • Try with this idiom: `\@ref(fig:Waffleplot-school)` – Ric Jan 18 '23 at 14:05
  • As stated, I have tried this, but it yields \ref(fig:Waffleplot-school) instead of the reference itself. Do you know why? – Marja van der Wind Jan 18 '23 at 14:07
  • Ok i read @ref without \. Let me try. I remember using pdf_document2 and \@ref idiom worked. – Ric Jan 18 '23 at 14:09
  • Oh I see, I think the \ was removed by the stackoverflow renderer, I changed it to \@ but meant that all along. – Marja van der Wind Jan 18 '23 at 14:45
  • 1
    Can you provide a minimal complete example of a rmarkdown file with simple plots (say `plot(1:10)`) with reference that showcases the problem? – shafee Jan 18 '23 at 14:54
  • Does the problem happen with a single file, or do you need to have your multiple-file inputs? – user2554330 Jan 18 '23 at 15:36
  • @Shafee thanks, I understand that I need to provide a minimal example, but I couldn't manage to do so. I do not really have a clue what my problem is and if I try to reproduce it in small existing datasets, it does not occur. – Marja van der Wind Jan 18 '23 at 15:59
  • @user2554330 Indeed if I make a simpler case with one file only, this problem does not occur. I have worked with referencing in the past and the problem is in the fact that things get complex here with multiple files refering to each other and different output systems. – Marja van der Wind Jan 18 '23 at 16:00
  • 1
    I think you need to post a complete example here if you want help. Here's what I'd suggest: 1. Keep the main file and the single file with the reference that doesn't work. Delete the lines that run the other files. Make sure you still have the problem. 2. Delete everything from the two files except the minimal amount to show the error. 3. Post the two files here, along with a description of how you run them. – user2554330 Jan 18 '23 at 16:24

1 Answers1

1

can you try this:

---
output: 
  bookdown::pdf_document2:
    number_sections: true
    keep_tex: true
    fig_caption: yes
    latex_engine: pdflatex
    extra_dependencies: ["flafter"]