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

问题描述

当我使用 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,g = c(rep(groups[1],15),rep(groups[2],rep(groups[3],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-@R_167_4045@ion
================
exname: example
extype: schoice
exsolution: `r paste(solution)`
exshuffle: 4

我最终得到了两个奇怪的东西,首先是传说。其次是答案选项。

enter image description here

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

解决方法

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

进一步说明:

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