The primary goal of ggcheck is to help tutorial authors inspect and test properties of [ggplot2] plots. The examples below demonstrate how ggcheck can be used in general; for more information about using gradethis in learnr tutorials, please see the gradethis package documentation.
Suppose an exercise asks students to create the following plot of engine displacement vs highway miles per gallon ratings.
library(ggplot2) p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point(mapping = aes(color = class)) + geom_smooth(se = FALSE, method = "lm") p
We can use ggcheck to test that students used geom_point()
library(ggcheck) uses_geoms(p, "point", exact = FALSE)
or that both geom_point()
and geom_smooth()
were used
uses_geoms(p, c("point", "smooth"), exact = FALSE)
or that exactly both geom_point()
and geom_smooth()
were used and in that order.
uses_geoms(p, c("point", "smooth"), exact = TRUE)
Similarly, we can test that a linear model was used for the smoothing method and the confidence interval was not displayed:
uses_geom_param(p, "smooth", list(se = FALSE, method = "lm"))
There's a lot more that ggcheck can do. Read more in the full function listing.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.