Skip to content

Commit

Permalink
Move rmd example into man/examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Jan 16, 2025
1 parent 3a1572b commit daf292a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The above quiz is created from the R Markdown document below. Knitting the docum

```{r, echo = FALSE, results="asis"}
cat("````\n")
cat(readLines("inst/examples/draw-scatterplots.Rmd"), sep = "\n")
cat(readLines("man/examples/draw-scatterplots.Rmd"), sep = "\n")
cat("````")
```

59 changes: 59 additions & 0 deletions man/examples/draw-scatterplots.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Drawing a scatterplot
output:
moodlequiz::moodlequiz:
replicates: 5
moodlequiz:
category: datavis-scatterplots
---

# Data

```{r setup, include = FALSE}
library(tidyverse)
library(rlang)
library(moodlequiz)
knitr::opts_chunk$set(echo = FALSE,
results = "hide",
fig.height = 4,
fig.width = 5,
fig.path = "",
fig.cap = "",
fig.align = "center")
```

```{r data}
cols <- colnames(mtcars)
cats <- c("cyl", "vs", "am", "gear", "carb")
nums <- setdiff(cols, cats)
x <- sample(nums, 1)
y <- sample(setdiff(nums, x), 1)
color <- sample(cats, 1)
size <- sample(setdiff(nums, c(x, y)), 1)
```

You have been asked to analyse the `mtcars` data. The variables and the class types of the data is shown below.

```{r, echo = TRUE, results = "show"}
str(mtcars)
```

# Plot

As a starting point, you decide to draw a scatter plot for some variables. Complete the code below to get the target plot below:

```r
ggplot(mtcars, aes(x = `r cloze(x, cols)`,
y = `r cloze(y, cols)`,
color = factor(`r cloze(color, cols)`),
size = `r cloze(size, cols)`)) +
`r cloze("geom_point", ls(envir = as.environment("package:ggplot2"), pattern = "^geom_"))`()
```


```{r, results = "show"}
ggplot(mtcars, aes(!!sym(x), !!sym(y), size = !!sym(size), color = factor(!!sym(color)))) +
geom_point() +
theme(plot.background = element_rect(color = "black"))
```

0 comments on commit daf292a

Please sign in to comment.