0

I try to use more than one question with (gg)plots in an R-exam using exams2nops(). However, the first plot seems to be cached and displayed instead of all further plots, too.

Edit: with "more than one question" I meant an exam with several questions containing plot per person and each of them with randomized differences between persons.

sammerk
  • 1,143
  • 1
  • 9
  • 23

1 Answers1

1

The templates available on the R/exams web page provide several examples how to include randomized graphics in the exercises. As a concrete example see: http://www.R-exams.org/templates/scatterplot/.

This uses base graphics for producing the scatterplot. If you want to use ggplot2 instead you can replace the "scatterplot" chunk plot(x, y), e.g., with:

d <- data.frame(x = x, y = y)
library("ggplot2")
theme_set(theme_minimal())
ggplot(d, aes(x = x, y = y)) + geom_point()

Both yield the desired randomized output.

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • Thanks @Achim for the link to the templates! Meanwhile I figured out that the error was caused by multiple empty chunk labels. – sammerk Jan 12 '19 at 13:12