为什么在绘制 ggplot2 绘图时 exams 会打印图形图例?

Why does `exams` prints the figure legend when plotting `ggplot2` plots?

当我使用 exams2nops()exams2moodle()

Question
========
Some questions...
pacman::p_load(ggplot2, magrittr)
#make sample data
groups <- letters[23:26]

df <- data.frame(x = rnorm(n = 60,mean = 3.5, sd = 3.4),
                 y = rnorm(n = 60,mean = 3.5, sd = 3.4),
                 g = c(rep(groups[1],15),rep(groups[2],15),rep(groups[3],15),rep(groups[4],15)))


colors_pal <- c("#264653", "#2a9d8f", "#457b9d", "#e76f51")

plot_reg_line_equation <- function(df, groups, colors_pal) {
    ggplot(data = dplyr::filter(.data = df, g==groups), aes(x = x, y = y)) +
    geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
    geom_point() + 
    ggtitle(label = paste0(groups)) +
    jtools::theme_apa() +
    theme(axis.line = element_line(colour = "black"),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          panel.border = element_blank(),
          panel.background = element_blank())
  }

lapply(groups, plot_reg_line_equation, df = df) %>% patchwork::wrap_plots()
solution <- groups==groups[1]
exams::answerlist(groups, markup = "markdown")
Solution
========
Some solution feedback.


Meta-information
================
exname: example
extype: schoice
exsolution: `r paste(solution)`
exshuffle: 4

我得到了两个奇怪的东西,第一个是传说。其次是答案选项。

注意:我注意到,如果我在情节块之后立即有某种文本,它不会产生图例(例如,即使它是 html <br>),但是,我想理解这种行为。

只需在生成图形的 R 代码块的选项中设置 fig.cap = ""。与往常一样 R/Markdown 这会抑制图形的标题。

补充说明:

  • 您还没有显示当前使用的选项。
  • exsolution 中,您需要 mchoice2string() 而不是 paste()