diff --git a/.DS_Store b/.DS_Store index 4190f20..e2425d2 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/tutorials/.DS_Store b/tutorials/.DS_Store index c90d532..d245c1c 100644 Binary files a/tutorials/.DS_Store and b/tutorials/.DS_Store differ diff --git a/tutorials/css/bg6-01.png b/tutorials/css/bg6-01.png new file mode 100644 index 0000000..5ad44f5 Binary files /dev/null and b/tutorials/css/bg6-01.png differ diff --git a/tutorials/css/bg7-01.png b/tutorials/css/bg7-01.png new file mode 100644 index 0000000..6222a64 Binary files /dev/null and b/tutorials/css/bg7-01.png differ diff --git a/tutorials/css/bg8-01.png b/tutorials/css/bg8-01.png new file mode 100644 index 0000000..48bf39f Binary files /dev/null and b/tutorials/css/bg8-01.png differ diff --git a/tutorials/css/bg9-01.png b/tutorials/css/bg9-01.png new file mode 100644 index 0000000..07e16a1 Binary files /dev/null and b/tutorials/css/bg9-01.png differ diff --git a/tutorials/css/custom.css b/tutorials/css/custom.css index ce77290..8110329 100644 --- a/tutorials/css/custom.css +++ b/tutorials/css/custom.css @@ -26,7 +26,7 @@ p.caption { } body { - background-image: url('bg5.png'); + background-image: url('bg9-01.png'); background-attachment: fixed; background-size: 100%; } @@ -51,7 +51,7 @@ hr { code { background-color: #c34a79; - color: black; + color: white; font-family: Roboto Mono; } diff --git a/tutorials/css/r_first_then.png b/tutorials/css/r_first_then.png new file mode 100644 index 0000000..4df61f0 Binary files /dev/null and b/tutorials/css/r_first_then.png differ diff --git a/tutorials/css/we_belive_in_you.html b/tutorials/css/we_belive_in_you.html new file mode 100644 index 0000000..689b47c --- /dev/null +++ b/tutorials/css/we_belive_in_you.html @@ -0,0 +1,2582 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + stats-illustrations/monster_support.jpg at master · allisonhorst/stats-illustrations + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + allisonhorst  /   + stats-illustrations  /   + +
+
+ + + +
+ + +
+ + +
+ + + +
+
+ Tip: + Type # to search pull requests +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type # to search issues +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type # to search discussions +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type ! to search projects +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type @ to search teams +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type @ to search people and organizations +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type > to activate command mode +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Go to your accessibility settings to change your keyboard shortcuts +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type author:@me to search your content +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type is:pr to filter to pull requests +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type is:issue to filter to issues +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type is:project to filter to projects +
+
+ Type ? for help and tips +
+
+
+ +
+
+ Tip: + Type is:open to filter to open content +
+
+ Type ? for help and tips +
+
+
+ +
+ +
+
+ We’ve encountered an error and some results aren't available at this time. Type a new search or try again later. +
+
+ + No results matched your search + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + Search for issues and pull requests + + # + + + + Search for issues, pull requests, discussions, and projects + + # + + + + Search for organizations, repositories, and users + + @ + + + + Search for projects + + ! + + + + Search for files + + / + + + + Activate command mode + + > + + + + Search your issues, pull requests, and discussions + + # author:@me + + + + Search your issues, pull requests, and discussions + + # author:@me + + + + Filter to pull requests + + # is:pr + + + + Filter to issues + + # is:issue + + + + Filter to discussions + + # is:discussion + + + + Filter to projects + + # is:project + + + + Filter to open issues, pull requests, and discussions + + # is:open + + + + + + + + + + + + + + + + +
+
+
+ +
+ + + + + + + + + + +
+ + + + +
+
+
+ + + + + + + + + +
+ +
+ +
+

+ + + / + + stats-illustrations + + + Public +

+ +
+ +
    + + + +
  • + +
    + + + + + Unwatch + + + + + 105 + + + + +
    +
    +

    Notifications

    + +
    + +
    +
    + + + + + + + + +
    + + +
    +
    +
    + + + + +
    +
    +
    + + + +
  • + +
  • + Fork + 183 + + +
  • + +
  • + + +
    +
    + + +
    +
    + +
    +
    + + + + +
    + +
    +
    + + + + + + + +
    + +
    +
    +
    +
    +
    +
  • + + + +
+ +
+ +
+
+ + + + +
+ + + +
+ Open in github.dev + Open in a new github.dev tab + + + + + + +
+ + +
+ + + + + + +Permalink + +
+ +
+
+ + + master + + + + +
+
+
+ Switch branches/tags + +
+ + + +
+ +
+ +
+ + +
+ +
+ + + + + + + + + + + + + + + +
+ + +
+
+
+
+ +
+ +
+ + + Go to file + + +
+ + + + + +
+
+
+ + + + + + + + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + + + + + + + +
+ +
+ + +
+ + 1.23 MB +
+ +
+ + + + +
+ + + + +
+ +
+
+ +
+ +
+
+ + + +
+ +
+ monster_support.jpg +
+
+ +
+ + + + +
+ + +
+ + +
+
+ + +
+ +
+ + +
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorials/css/we_belive_in_you.jpeg b/tutorials/css/we_belive_in_you.jpeg new file mode 100644 index 0000000..a63effd Binary files /dev/null and b/tutorials/css/we_belive_in_you.jpeg differ diff --git a/tutorials/tutorials.Rmd b/tutorials/tutorials.Rmd index 6d236a2..da7a0f8 100644 --- a/tutorials/tutorials.Rmd +++ b/tutorials/tutorials.Rmd @@ -3,9 +3,10 @@ title: "Math Lessons" author: "R-Girls" output: learnr::tutorial: + progressive: true + allow_skip: true css: css/custom.css runtime: shiny_prerendered - --- ```{r setup, include=FALSE} @@ -19,82 +20,161 @@ knitr::opts_chunk$set(echo = FALSE) ``` +## Welcome + +Hello everyone! This tutorial was created by [R Girls School Network](https://r-girls.github.io/website/) to promote the use of R in secondary schools for girls. + +![](css/we_belive_in_you.jpeg){style="width: 600px; "} + + +### How does this tutorial work? + +You don't need to install R/RStudio locally to run these lessons. These interactive lessons relies on [learnr package](https://rstudio.github.io/learnr/) to create an interactive code chunks, where we will run, edit, or write our own code. An example is shown below with some pre-populated code. +Give it a try and click the 'Run Code' button in the top right to see the outcome of this code to make a ggplot graph! + +```{r demo-1, exercise = TRUE} +mpg$class = with(mpg, reorder(class, hwy, median)) + +p <- mpg %>% + ggplot( aes(x=class, y=hwy, fill=class)) + + geom_violin() + + xlab("class") + + theme(legend.position="none") + + xlab("") + p + +``` + +There will be occasions where you will be asked to "fill in the blanks" for practice but there were also a "Hint" and/or "Solution" button - in case get stuck. You can find the hint or solution by clicking on that button. Go a head and try it below, as if you are asked to **update the point color to "orange" and the point size to 4** in this ggplot graph: + +```{r demo-2, exercise = TRUE} +ggplot(data = mtcars, aes(x = wt, y = mpg)) + + geom_point() +``` + +```{r demo-2-hint} +ggplot(data = mtcars, aes(x = wt, y = mpg)) + + geom_point(color = "______", size = _) +``` + +```{r demo-2-solution} +ggplot(data = mtcars, aes(x = wt, y = mpg)) + + geom_point(color = "orange", size = 4) +``` + +### A Big Thank you + +This work was inspired by a tutorial made by the wonderful [Allison Horst](https://www.allisonhorst.com/) in R-Ladies Dammam & R-Ladies Tunis, which can be accessed in [this repository](https://github.com/RLadies-Saudi/r-ladies-Dammam_tunis-2021). + +Throughout this tutorial we use different resources and packages, which includes: + +1. tidyverse: Wickham et al., (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686, + +2. dplyr: Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2020). dplyr: A Grammar of Data Manipulation. R package version 1.0.2. + +3. ggplot2: H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016. + +4. learnr: Barret Schloerke, JJ Allaire and Barbara Borges (2020). learnr: Interactive Tutorials for R. R package version. 0.10.1. + +5. The Turing Way Community. (2021, November 10). The Turing Way: A handbook for reproducible, ethical and collaborative research. Zenodo. + +### License + +All materials are licensed under a Creative Commons Attribution 4.0 International (CC BY 4.0), which means you can use, modify it and adapt it with attribution. + +### Citation + +We genrate a DOI to the lessons through Zenodo archive using [DOI: 10.5281/zenodo.6436861](https://zenodo.org/record/6436861#.YlxG75NBxhE). DOIs allow us to archive this open source project and ensure that the work is tracked through metrics. If you use any of our lessons, please include the following attribution: + +> RGirls Community. (2022, April 10). RGirls Lessons. Zenodo. + ## Generating Sequences Part 1 +#### Lesson objectives + +- Generating sequences using R code -### Lesson objectives -- Generating sequences using R code +#### Packages used in this lesson: -### Packages used in this lesson: +- `tidyverse` -- `tidyverse` +#### Success criteria -### Success criteria -* Generate different sequences using R code +- Generate different sequences using R code -### Keywords -* sequence -* term = the numbers in the sequence -* nth term +#### Keywords + +- sequence +- term = the numbers in the sequence +- nth term ### Worked Example 1 First we will tell R to generate a sequence. This is how you generate a sequence of numbers from 1 to 100 where the terms increase by 1. + ```{r chunk11, exercise=TRUE} seq(from=1,to=100,by=1) ``` -Use the above example R code in chunk1 to generate the following sequences. Remember to edit the numbers in the code. +Use the above example R code in chunk1 to generate the following sequences. Remember to edit the numbers in the code. + +### Activity 1 Questions -#### Activity 1 Questions Q1 Generate a sequence from 1 to 100 where the terms increase by 10 ```{r chunk21, exercise=TRUE} ``` Q2 Generate a sequence from 5 to 95 where the terms increase by 5. + ```{r chunk31, exercise=TRUE} ``` Q3 Generate a sequence from 3 to 399 where the terms increase by 4. + ```{r chunk41, exercise=TRUE} ``` Q4 Generate a sequence from 1 to 9 where the terms increase by 3. + ```{r chunk51, exercise=TRUE} ``` - ### Worked Example 2 + Now we will generate a sequence that starts from a number and goes up to the nth term, where the nth term is for example 10. For example a sequence from 1 where the terms go up by 1 till the 10th term. + ```{r chunk61, exercise=TRUE} seq(from=1, length.out=10, by=1) ``` -Use the above example R code in chunk6 to generate the following sequences. +Use the above example R code in chunk6 to generate the following sequences. Knit your document after each question to check your sequence. -#### Activity 2 Questions +### Activity 2 Questions + Q1 Generate a sequence from 1 where the terms go up by 4 up to the 100th term ```{r chunk71, exercise=TRUE} ``` Q2 Generate a sequence from 5 where the terms go up by 10 up to the 89th term + ```{r chunk81, exercise=TRUE} ``` Q3 Generate a sequence from 3 where the terms go up by 3 up to the 33rd term + ```{r chunk91, exercise=TRUE} ``` - ### Worked Example 3 + So the terms have increased by a particular number, but we can also decrease by a number and produce a backward sequence. For example, we can sequence from 100 to 1 by -1 @@ -103,47 +183,51 @@ For example, we can sequence from 100 to 1 by -1 seq(from=100, to=1, by=-1) ``` - Use the above example R code in chunk10 to answer the following questions. Knit your document after each question to check your sequence is correct. -#### Activity 3 Questions +### Activity 3 Questions Q1 Generate a sequence that goes down from 50 to 0 where the terms go down by 5. + ```{r chunk111, exercise=TRUE} ``` Q2 Generate a sequence from 10 to -10 where the terms go down by 1. + ```{r chunk121, exercise=TRUE} ``` Q3 Generate a sequence that goes down from 20 to 10 where the terms go down by 2. + ```{r chunk141, exercise=TRUE} ``` - ## Generating Sequences Part 2 -### Lesson objectives -- Investigating sequences +#### Lesson objectives -### Packages used in this lesson: +- Investigating sequences -- `tidyverse` +#### Packages used in this lesson: -### Success criteria -* Find the relationship between the terms -* Does a number lie in a sequence -* Find a missing term in the sequence +- `tidyverse` -### Keywords -* sequence -* term -* nth term +#### Success criteria +- Find the relationship between the terms +- Does a number lie in a sequence +- Find a missing term in the sequence + +#### Keywords + +- sequence +- term +- nth term + +### Worked Example 1 -#### Worked Example 1 This is how you find the difference between the terms in a sequence. The sequence is 3, 7, 11, 15. @@ -157,29 +241,32 @@ diff(x) The R code tells you the difference between each number in the sequence. -##### Activity 1 Questions +### Activity 1 Questions Now use the above example R code in chunk1 to find the difference between the terms in the following sequences -Knit the document after each question to see the answer. Check your answer. +Knit the document after each question to see the answer. Check your answer. + +Q1 2,7,12,17,22 -Q1 2,7,12,17,22 ```{r chunk2, exercise=TRUE} ``` -Q2 3,9,15,21,27 +Q2 3,9,15,21,27 + ```{r chunk3, exercise=TRUE} ``` Q3 1,4,10,19,31 + ```{r chunk4, exercise=TRUE} ``` - #### Worked Example 2 + Now we will see if a number lies in a sequence. -First we will generate the first 20 terms of the sequence 3,7,11,15 and then we will see if the numbers 55 and 56 lie in the sequence. The computer will generate the sequence and if it finds the number it will report it below the sequence. If it does not find it then it will say numeric (0). +First we will generate the first 20 terms of the sequence 3,7,11,15 and then we will see if the numbers 55 and 56 lie in the sequence. The computer will generate the sequence and if it finds the number it will report it below the sequence. If it does not find it then it will say numeric (0). ```{r chunk5, exercise=TRUE} x <- seq(from=3, length.out=20, by=4) @@ -192,20 +279,21 @@ Use the above example R code in chunk5 to answer the following questions. Remember to tell R how many terms you want it to generate by editing the length.out number. Remember to tell R what numbers to look for in the sequence by editing the x== numbers. +### Activity 2 Questions -##### Activity 2 Questions Q1 Generate the first 100 terms of the sequence 3,7,11,15 and see if the numbers 117 and 395 lie in the sequence. Do they? ```{r chunk6, exercise=TRUE} ``` - #### Worked Example 3 -Now we will find the missing number in a sequence. Our sequence is 4, ?, 16, 22. Term 2 is missing. So we generate the sequence based on what we know which is that the difference between 16 and 22 is 6. The computer will put in the missing term. + +Now we will find the missing number in a sequence. Our sequence is 4, ?, 16, 22. Term 2 is missing. So we generate the sequence based on what we know which is that the difference between 16 and 22 is 6. The computer will put in the missing term. ```{r chunk7, exercise=TRUE} seq(from=4, to=22, by=6) ``` + Answer: The missing term is 10. Use the above example R code to answer the following questions. @@ -213,6 +301,7 @@ Use the above example R code to answer the following questions. Remember to knit to see your results. ##### Activity 3 Questions + Q1 What is the missing term in the sequence 3,12,?,30. ```{r chunk8, exercise=TRUE} @@ -220,30 +309,29 @@ Q1 What is the missing term in the sequence 3,12,?,30. ## Using Pythagoras' Theorem -### Lesson Objective +#### Lesson Objective Use Pythagoras' Theorem to find the lengths of missing sides of a right angle triangle -### Packages used in this lesson: +#### Packages used in this lesson: -- `tidyverse` +- `tidyverse` -### Success criteria +#### Success criteria Write the R code to work out the missing side Calculate the missing side -### Keywords +#### Keywords -* Pythagoras theorem -* Length of a side -* Hypotenuse -* square -* square root +- Pythagoras theorem +- Length of a side +- Hypotenuse +- square +- square root - -#### Worked Example 1: Finding the hypotenuse +### Worked Example 1: Finding the hypotenuse First knit the document so that you can see images of the triangles and the formulae you will be working with. @@ -253,7 +341,6 @@ The formula to find c is: $$c = \sqrt{a^2 + b^2}$$ Check how the formula is written in the output . - ```{r setup2, echo=F, exercise=TRUE} x <- c(0, 0.5, 0) @@ -268,7 +355,7 @@ text(0.5,0.5, "c") The length of side c is missing. -The R code in chunk2 below works out the missing side c. Click on the little arrow on the right of the chunk to run the code. +The R code in chunk2 below works out the missing side c. Click on the little arrow on the right of the chunk to run the code. The answer will be shown below the code chunk. @@ -306,7 +393,6 @@ Use the code in chunk2 to help you. ``` - #### Worked Example 2 Use Pythagoras' theorem to find one of the other sides. @@ -352,7 +438,6 @@ Use the R code from the above examples to help you find the missing sides in the | | 9 | 49 | | 10 | 10 | | - Find length b when a=36 and c=81 ```{r lesson3b, exercise=TRUE} @@ -366,52 +451,49 @@ Find length a when b=9 and c=49 a ``` - - Find length c when a=10 and b=10 ```{r lesson3d, exercise=TRUE} c ``` - ### Extension -Can you round your answers from code chunks 7, 8 and 9 to 2 decimal places? Use the space below and knit the document to see if you have been successful. +Can you round your answers from code chunks 7, 8 and 9 to 2 decimal places? Use the space below and knit the document to see if you have been successful. ```{r lesson3e, exercise=TRUE} ``` +## Finding the Equation - Part 1 +#### Lesson objectives -## Finding the Equation - Part 1 +- Plotting straight line graphs $y=mx+c$ -### Lesson objectives -- Plotting straight line graphs $y=mx+c$ +#### Packages used in this lesson: -### Packages used in this lesson: +- `tidyverse` -- `tidyverse` +#### Success criteria -### Success criteria -- Plot a straight line graph $y = mx+c$ -- Compare graphs +- Plot a straight line graph $y = mx+c$ +- Compare graphs -### Keywords -* slope -* gradient = m -* intercept = c -* x-axis -* y-axis +#### Keywords +- slope +- gradient = m +- intercept = c +- x-axis +- y-axis #### Worked Example 1 + This is a worked example for you to follow. We will show you how to plot the line graph for $y=2x + 5$. - ```{r lesson4a, exercise=TRUE } x <- seq(from=-4, to=4, by=1) # sequence the x-axis from -4 to 4 y <- 2*x+5 @@ -425,15 +507,15 @@ ggplot(mydata) + Now close the image by clicking on the X to the right of the graph -#### Activity1: +### Activity1: + Write your own code to draw the following graphs. Use code chunk1 from the example above to help you. -1. y = 2x (in code chunk2) -2. y = 3x + 10 (in code chunk3) -3. y = 5x + 2.5 (in code chunk4) - +1. y = 2x (in code chunk2) +2. y = 3x + 10 (in code chunk3) +3. y = 5x + 2.5 (in code chunk4) ```{r lesson4b, exercise=TRUE} ``` @@ -445,14 +527,13 @@ Use code chunk1 from the example above to help you. ``` #### Worked Example 2 -Drawing more than one line on a graph helps us to compare the lines and see what is the same and what is different. -Here is a worked example for four different lines. -1. y=3x+0 -2. y=3x+1 -3. y=3x+2 -4. y=3x+3 +Drawing more than one line on a graph helps us to compare the lines and see what is the same and what is different. Here is a worked example for four different lines. +1. y=3x+0 +2. y=3x+1 +3. y=3x+2 +4. y=3x+3 ```{r lesson4e, exercise=TRUE} x <- seq(-4, 4) # sequence from -4 to 4 @@ -469,21 +550,23 @@ ggplot(mydata) + geom_vline (xintercept = 0, col='black')+ geom_hline (yintercept = 0, col='black') ``` -Question: From the graph what looks the same and what looks different about these lines? + +Question: From the graph what looks the same and what looks different about these lines? Answer: -#### Activity2: +### Activity2: + Draw the following lines on a graph -1. y=1x+5 -2. y=2x+5 -3. y=3x+5 -4. y=4x+5 +1. y=1x+5 +2. y=2x+5 +3. y=3x+5 +4. y=4x+5 -Use code chunk5 from the example above to help you. Remember to update the R code with the new lines. +Use code chunk5 from the example above to help you. Remember to update the R code with the new lines. -Run the code. Knit the document. +Run the code. Knit the document. ```{r lesson4f, exercise=TRUE} ``` @@ -493,30 +576,33 @@ Question: What is the same and what is different about the lines? ```{r lesson4g, exercise=TRUE} ``` - ## Finding the Equation - Part 2 -### Lesson objectives +#### Lesson objectives + Plotting and finding the equations of straight line graphs $y=mx+c$ -### Packages used in this lesson: +#### Packages used in this lesson: -- `tidyverse` +- `tidyverse` -### Success criteria -* Plot a straight line graph $y = mx+c$ -* Plot straight line graphs $y = mx+c$ with different intercepts -* Plot a straight line graph $y = mx+c$ with a negative gradient -* Find the equations of straight line graphs +#### Success criteria -### Keywords -* slope -* gradient -* intercept -* x-axis -* y-axis +- Plot a straight line graph $y = mx+c$ +- Plot straight line graphs $y = mx+c$ with different intercepts +- Plot a straight line graph $y = mx+c$ with a negative gradient +- Find the equations of straight line graphs + +#### Keywords + +- slope +- gradient +- intercept +- x-axis +- y-axis + +### Worked Example 1 -#### Worked Example 1 This is a worked example for you to follow. We will show you how to plot the line graph for y=2x + 5. @@ -533,16 +619,15 @@ ggplot(mydata) + geom_hline (yintercept = 0, col='black') ``` +### Worked Example 2 -#### Worked Example 2 We will now see what happens when you change the intercept c to a negative value. -1. y=3x+5 -2. y=3x-5 +1. y=3x+5 +2. y=3x-5 Run the code in chunk2 by clicking on the little arrow on the right of the code chunk. - ```{r lesson5b, exercise=TRUE} x <- seq(-4, 4) # sequence from -4 to 4 y1 <- 3*x+5 @@ -554,49 +639,45 @@ ggplot(mydata) + geom_vline (xintercept = 0, col='black')+ geom_hline (yintercept = 0, col='black') ``` -Question: What is the same and what is different about these lines? +Question: What is the same and what is different about these lines? Knit your document and check the output. +### Activity 1 -#### Activity 1 - -Draw these lines on a graph. Use the R code from chunk2 to help you. Remember to update the code with these new lines. +Draw these lines on a graph. Use the R code from chunk2 to help you. Remember to update the code with these new lines. -1. y=x+10 -2. y=x-10 +1. y=x+10 +2. y=x-10 ```{r lesson5c, exercise=TRUE} ``` -Question: What is the same and what is different about these lines? +Question: What is the same and what is different about these lines? +### Activity 2 -#### Activity 2 -Now we will investigate m (the gradient). Draw these lines on a graph. Use R code from chunk2 to help you. +Now we will investigate m (the gradient). Draw these lines on a graph. Use R code from chunk2 to help you. Run the code and knit the document. -1. y=-2x+5 -2. y= 2x+5 +1. y=-2x+5 +2. y= 2x+5 ```{r lesson5d, exercise=TRUE} ``` -Question: What is the same and what is different about these lines? - +Question: What is the same and what is different about these lines? -#### Activity 3 Answer the following questions +### Activity 3 Answer the following questions ```{r lesson5e, exercise=TRUE} cat ("Q1 In the equation y=mx+c, what happens when you change c?") cat ("Q2 What happens when you change m?") ``` - - -#### Activity 4: Work out the equation from a line graph +### Activity 4: Work out the equation from a line graph Write down the equations of the following four lines on the graph below. @@ -616,42 +697,35 @@ ggplot() + geom_hline (yintercept=0, col='black') ``` - ## Representing Data with boxplots +#### Lesson objectives -### Lesson objectives - -- To understand how to visualise the shape of data using box plots\ -- To produce box plots and the related five number summary\ -- To interpret box plots\ +- To understand how to visualise the shape of data using box plots\ +- To produce box plots and the related five number summary\ +- To interpret box plots\ -### Packages used in this lesson: +#### Packages used in this lesson: -- `tidyverse` -- `astsa` +- `tidyverse` +- `astsa` -### Success criteria +#### Success criteria -* Draw a box plot using R code -* Produce a five number summary using R code -* Read data from a box plot -* Compare two box plots +- Draw a box plot using R code +- Produce a five number summary using R code +- Read data from a box plot +- Compare two box plots +#### Keywords -### Keywords - -box plot, -minimum, maximum, lower quartile, median, upper quartile, five number summary, inter-quartile range, range - +box plot, minimum, maximum, lower quartile, median, upper quartile, five number summary, inter-quartile range, range ### What is a box plot -A box plot is a way to show the shape or distribution of a set of data. -It shows five useful features of the data, known as the five number summary. +A box plot is a way to show the shape or distribution of a set of data. It shows five useful features of the data, known as the five number summary. -Minimum - the smallest value\ -Maximum - the largest value\ +Minimum - the smallest value  Maximum - the largest value\ Median - the middle or 50% value\ Lower quartile - the value half way between the minimum and the median or 25% value\ Upper quartile - the value half way between the median and the maximum or 75% value\ @@ -664,7 +738,7 @@ Zaynab keeps a record of her journey times to school each morning. The times are 29,21,16,25,21,19,18,30,21,21,12,26,19,21,20,19,30,29,16,21,18,18,27,18,20 -Let us draw a box plot and obtain the five number summary and the inter-quartile range (IQR). We will do this in three steps. +Let us draw a box plot and obtain the five number summary and the inter-quartile range (IQR). We will do this in three steps. The R code in chunk1 tells R to store all the times into a variable called y and then to use these times to draw a box plot of the data. @@ -678,7 +752,7 @@ Here is a simple trick to get gridlines on the plot. The code in chunk2 tells R to use the numbers it store in variable y to draw a box plot and then to add grid lines. -Click on the little arrow on the right of the code chunk. The box plot will be drawn below the chunk. +Click on the little arrow on the right of the code chunk. The box plot will be drawn below the chunk. ```{r lesson6b, exercise=TRUE} # we can calculate the five number summary like this @@ -689,14 +763,12 @@ boxplot(y, xlab="Times (mins)", horizontal=T, add=T) We can also get R to calculate the five number summary for us. - ```{r lesson6c, exercise=TRUE} # we can calculate the five number summary like this summary(y) # five number summary but also provides the mean IQR(y) # inter-quartile range ``` - ### Activity 1: Produce a box plot, the five number summary and IQR of the following data @@ -707,8 +779,7 @@ The times are recorded to the nearest minute. 85,124,55,140,120,61,95,105,118,180,55,78,130,112,70,126,60,90,115,60,142,100,105,65,100,75 - -Use the R code in chunk1 to help you draw the box plot. Remember to replace the example data with the new dataset. +Use the R code in chunk1 to help you draw the box plot. Remember to replace the example data with the new dataset. ```{r lesson6d, exercise=TRUE} ``` @@ -723,18 +794,16 @@ Now calculate the five number summary using code in chunk3 ```{r lesson6af, exercise=TRUE} ``` - ### Worked Example 2 Below are the percentage exam marks out of 100 for Maths and English. -Maths (%): 98,79,51,54,62,61,56,87,70,60,93,51,52,54,68 +Maths (%): 98,79,51,54,62,61,56,87,70,60,93,51,52,54,68 -English (%): 37,50,58,45,93,47,47,45,38,61,65,46,97,99,54 +English (%): 37,50,58,45,93,47,47,45,38,61,65,46,97,99,54 Produce two box plots side by side - ```{r l4, exercise=TRUE} maths <- c(98,79,51,54,62,61,56,87,70,60,93,51,52,54,68) english <- c(37,50,58,45,93,47,47,45,38,61,65,46,97,99,54) @@ -755,11 +824,11 @@ What are the inter-quartile ranges Below are the heights of boys and girls of a similar age. -Boys (cm): 181,157,159,179,186,159,178,162,137,184,140,173,176 +Boys (cm): 181,157,159,179,186,159,178,162,137,184,140,173,176 -Girls (cm): 172,151,176,159,139,179,178,162,134,166,164,172,170 +Girls (cm): 172,151,176,159,139,179,178,162,134,166,164,172,170 -Produce two box plots side by side with a grid and answer the following questions. +Produce two box plots side by side with a grid and answer the following questions. Remember to replace the example data with the new information (boys, girls, heights, data) @@ -770,20 +839,18 @@ Remember to replace the example data with the new information (boys, girls, heig Are the statements below True or False - and explain why -1. The girls are taller on average - -2. Half the girls are over 165 cm tall - -3. The girls show less spread in height +1. The girls are taller on average -4. The boys show less spread in height +2. Half the girls are over 165 cm tall -5. The shortest person is a girl +3. The girls show less spread in height -6. The tallest person is a boy +4. The boys show less spread in height -7. Half the boys are over 172 cm tall +5. The shortest person is a girl -8. Half the girls are under 165cm tall +6. The tallest person is a boy +7. Half the boys are over 172 cm tall +8. Half the girls are under 165cm tall diff --git a/tutorials/tutorials.html b/tutorials/tutorials.html index 709d3bb..bcd95a4 100644 --- a/tutorials/tutorials.html +++ b/tutorials/tutorials.html @@ -11,8 +11,8 @@ - - + + Math Lessons @@ -119,28 +119,86 @@
+
+

Welcome

+

Hello everyone! This tutorial was created by R Girls School Network to promote the use of R in secondary schools for girls.

+

+
+

How does this tutorial work?

+

You don’t need to install R/RStudio locally to run these lessons. These interactive lessons relies on learnr package to create an interactive code chunks, where we will run, edit, or write our own code. An example is shown below with some pre-populated code. Give it a try and click the ‘Run Code’ button in the top right to see the outcome of this code to make a ggplot graph!

+
+
mpg$class = with(mpg, reorder(class, hwy, median))
+
+p <- mpg %>%
+  ggplot( aes(x=class, y=hwy, fill=class)) + 
+    geom_violin() +
+    xlab("class") +
+    theme(legend.position="none") +
+    xlab("")
+  p
+ +
+

There will be occasions where you will be asked to “fill in the blanks” for practice but there were also a “Hint” and/or “Solution” button - in case get stuck. You can find the hint or solution by clicking on that button. Go a head and try it below, as if you are asked to update the point color to “orange” and the point size to 4 in this ggplot graph:

+
+
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
+  geom_point()
+ +
+
+
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
+  geom_point(color = "______", size = _)
+
+
+
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
+  geom_point(color = "orange", size = 4)
+
+
+
+

A Big Thank you

+

This work was inspired by a tutorial made by the wonderful Allison Horst in R-Ladies Dammam & R-Ladies Tunis, which can be accessed in this repository.

+

Throughout this tutorial we use different resources and packages, which includes:

+
    +
  1. tidyverse: Wickham et al., (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686, https://doi.org/10.21105/joss.01686

  2. +
  3. dplyr: Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2020). dplyr: A Grammar of Data Manipulation. R package version 1.0.2. https://CRAN.R-project.org/package=dplyr

  4. +
  5. ggplot2: H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.

  6. +
  7. learnr: Barret Schloerke, JJ Allaire and Barbara Borges (2020). learnr: Interactive Tutorials for R. R package version. 0.10.1. https://CRAN.R-project.org/package=learnr

  8. +
  9. The Turing Way Community. (2021, November 10). The Turing Way: A handbook for reproducible, ethical and collaborative research. Zenodo. http://doi.org/10.5281/zenodo.3233853

  10. +
+
+
+

License

+

All materials are licensed under a Creative Commons Attribution 4.0 International (CC BY 4.0), which means you can use, modify it and adapt it with attribution.

+
+
+

Citation

+

We genrate a DOI to the lessons through Zenodo archive using DOI: 10.5281/zenodo.6436861. DOIs allow us to archive this open source project and ensure that the work is tracked through metrics. If you use any of our lessons, please include the following attribution:

+
+

RGirls Community. (2022, April 10). RGirls Lessons. Zenodo. https://doi.org/10.5281/zenodo.6436861

+
+
+

Generating Sequences Part 1

-
-

Lesson objectives

+
+

Lesson objectives

  • Generating sequences using R code
-
-

Packages used in this lesson:

+
+

Packages used in this lesson:

  • tidyverse
-
-

Success criteria

+
+

Success criteria

  • Generate different sequences using R code
-
-

Keywords

+
+

Keywords

  • sequence
  • term = the numbers in the sequence
  • @@ -150,58 +208,58 @@

    Keywords

    Worked Example 1

    First we will tell R to generate a sequence.

    -This is how you generate a sequence of numbers from 1 to 100 where the terms increase by 1. +

    This is how you generate a sequence of numbers from 1 to 100 where the terms increase by 1.

    seq(from=1,to=100,by=1)

    Use the above example R code in chunk1 to generate the following sequences. Remember to edit the numbers in the code.

    -
    -

    Activity 1 Questions

    +
    +
    +

    Activity 1 Questions

    Q1 Generate a sequence from 1 to 100 where the terms increase by 10

    -Q2 Generate a sequence from 5 to 95 where the terms increase by 5. +

    Q2 Generate a sequence from 5 to 95 where the terms increase by 5.

    -Q3 Generate a sequence from 3 to 399 where the terms increase by 4. +

    Q3 Generate a sequence from 3 to 399 where the terms increase by 4.

    -Q4 Generate a sequence from 1 to 9 where the terms increase by 3. +

    Q4 Generate a sequence from 1 to 9 where the terms increase by 3.

    -

    Worked Example 2

    Now we will generate a sequence that starts from a number and goes up to the nth term, where the nth term is for example 10.

    -For example a sequence from 1 where the terms go up by 1 till the 10th term. +

    For example a sequence from 1 where the terms go up by 1 till the 10th term.

    seq(from=1, length.out=10, by=1)

    Use the above example R code in chunk6 to generate the following sequences.

    Knit your document after each question to check your sequence.

    -
    -

    Activity 2 Questions

    +
    +
    +

    Activity 2 Questions

    Q1 Generate a sequence from 1 where the terms go up by 4 up to the 100th term

    -Q2 Generate a sequence from 5 where the terms go up by 10 up to the 89th term +

    Q2 Generate a sequence from 5 where the terms go up by 10 up to the 89th term

    -Q3 Generate a sequence from 3 where the terms go up by 3 up to the 33rd term +

    Q3 Generate a sequence from 3 where the terms go up by 3 up to the 33rd term

    -

    Worked Example 3

    So the terms have increased by a particular number, but we can also decrease by a number and produce a backward sequence.

    @@ -212,54 +270,55 @@

    Worked Example 3

    Use the above example R code in chunk10 to answer the following questions.

    Knit your document after each question to check your sequence is correct.

    -
    -

    Activity 3 Questions

    -Q1 Generate a sequence that goes down from 50 to 0 where the terms go down by 5. +
    +
    +

    Activity 3 Questions

    +

    Q1 Generate a sequence that goes down from 50 to 0 where the terms go down by 5.

    -Q2 Generate a sequence from 10 to -10 where the terms go down by 1. +

    Q2 Generate a sequence from 10 to -10 where the terms go down by 1.

    -Q3 Generate a sequence that goes down from 20 to 10 where the terms go down by 2. +

    Q3 Generate a sequence that goes down from 20 to 10 where the terms go down by 2.

-

Generating Sequences Part 2

-
-

Lesson objectives

+
+

Lesson objectives

  • Investigating sequences
-
-

Packages used in this lesson:

+
+

Packages used in this lesson:

  • tidyverse
-
-

Success criteria

+
+

Success criteria

  • Find the relationship between the terms
  • Does a number lie in a sequence
  • Find a missing term in the sequence
-
-

Keywords

+
+

Keywords

  • sequence
  • term
  • nth term
-
-

Worked Example 1

+
+
+

Worked Example 1

This is how you find the difference between the terms in a sequence.

The sequence is 3, 7, 11, 15.

Knit your document to see the sequence generated by the R code in chunk1.

@@ -269,24 +328,23 @@

Worked Example 1

The R code tells you the difference between each number in the sequence.

-
-
Activity 1 Questions
+
+
+

Activity 1 Questions

Now use the above example R code in chunk1 to find the difference between the terms in the following sequences

Knit the document after each question to see the answer. Check your answer.

-Q1 2,7,12,17,22 +

Q1 2,7,12,17,22

-Q2 3,9,15,21,27 +

Q2 3,9,15,21,27

-Q3 1,4,10,19,31 +

Q3 1,4,10,19,31

-
-

Worked Example 2

Now we will see if a number lies in a sequence.

@@ -300,14 +358,14 @@

Worked Example 2

Use the above example R code in chunk5 to answer the following questions.

Remember to tell R how many terms you want it to generate by editing the length.out number. Remember to tell R what numbers to look for in the sequence by editing the x== numbers.

-
-
Activity 2 Questions
+
+
+
+

Activity 2 Questions

Q1 Generate the first 100 terms of the sequence 3,7,11,15 and see if the numbers 117 and 395 lie in the sequence. Do they?

-
-

Worked Example 3

Now we will find the missing number in a sequence. Our sequence is 4, ?, 16, 22. Term 2 is missing. So we generate the sequence based on what we know which is that the difference between 16 and 22 is 6. The computer will put in the missing term.

@@ -330,23 +388,23 @@
Activity 3 Questions

Using Pythagoras’ Theorem

-
-

Lesson Objective

+
+

Lesson Objective

Use Pythagoras’ Theorem to find the lengths of missing sides of a right angle triangle

-
-

Packages used in this lesson:

+
+

Packages used in this lesson:

  • tidyverse
-
-

Success criteria

+
+

Success criteria

Write the R code to work out the missing side

Calculate the missing side

-
-

Keywords

+
+

Keywords

  • Pythagoras theorem
  • Length of a side
  • @@ -354,8 +412,9 @@

    Keywords

  • square
  • square root
-
-

Worked Example 1: Finding the hypotenuse

+
+
+

Worked Example 1: Finding the hypotenuse

First knit the document so that you can see images of the triangles and the formulae you will be working with.

This is a worked example for you to follow.

The formula to find c is: \[c = \sqrt{a^2 + b^2}\]

@@ -382,7 +441,6 @@

Worked Example 1: Finding the hypotenuse

The length of \(c = r round(c,2)\) cm

The inline code above tells R to round c to 2 decimal places. Knit the document to check this.

-

Activity1: Your turn

Run R code chunk3. This will draw you the triangle with the length of side c missing.

@@ -486,27 +544,27 @@

Extension

Finding the Equation - Part 1

-
-

Lesson objectives

+
+

Lesson objectives

  • Plotting straight line graphs \(y=mx+c\)
-
-

Packages used in this lesson:

+
+

Packages used in this lesson:

  • tidyverse
-
-

Success criteria

+
+

Success criteria

  • Plot a straight line graph \(y = mx+c\)
  • Compare graphs
-
-

Keywords

+
+

Keywords

  • slope
  • gradient = m
  • @@ -514,6 +572,7 @@

    Keywords

  • x-axis
  • y-axis
+

Worked Example 1

This is a worked example for you to follow.

@@ -531,8 +590,8 @@

Worked Example 1

Now close the image by clicking on the X to the right of the graph

-
-

Activity1:

+
+

Activity1:

Write your own code to draw the following graphs.

Use code chunk1 from the example above to help you.

    @@ -549,7 +608,6 @@

    Activity1:

    -

Worked Example 2

Drawing more than one line on a graph helps us to compare the lines and see what is the same and what is different. Here is a worked example for four different lines.

@@ -578,8 +636,9 @@

Worked Example 2

Question: From the graph what looks the same and what looks different about these lines?

Answer:

-
-

Activity2:

+
+
+

Activity2:

Draw the following lines on a graph

  1. y=1x+5
  2. @@ -598,21 +657,20 @@

    Activity2:

-

Finding the Equation - Part 2

-
-

Lesson objectives

+
+

Lesson objectives

Plotting and finding the equations of straight line graphs \(y=mx+c\)

-
-

Packages used in this lesson:

+
+

Packages used in this lesson:

  • tidyverse
-
-

Success criteria

+
+

Success criteria

  • Plot a straight line graph \(y = mx+c\)
  • Plot straight line graphs \(y = mx+c\) with different intercepts
  • @@ -620,8 +678,8 @@

    Success criteria

  • Find the equations of straight line graphs
-
-

Keywords

+
+

Keywords

  • slope
  • gradient
  • @@ -629,8 +687,9 @@

    Keywords

  • x-axis
  • y-axis
-
-

Worked Example 1

+
+
+

Worked Example 1

This is a worked example for you to follow.

We will show you how to plot the line graph for y=2x + 5.

@@ -646,8 +705,8 @@

Worked Example 1

-
-

Worked Example 2

+
+

Worked Example 2

We will now see what happens when you change the intercept c to a negative value.

  1. y=3x+5
  2. @@ -669,8 +728,8 @@

    Worked Example 2

    Question: What is the same and what is different about these lines?

    Knit your document and check the output.

-
-

Activity 1

+
+

Activity 1

Draw these lines on a graph. Use the R code from chunk2 to help you. Remember to update the code with these new lines.

  1. y=x+10
  2. @@ -681,8 +740,8 @@

    Activity 1

Question: What is the same and what is different about these lines?

-
-

Activity 2

+
+

Activity 2

Now we will investigate m (the gradient). Draw these lines on a graph. Use R code from chunk2 to help you.

Run the code and knit the document.

    @@ -694,16 +753,16 @@

    Activity 2

Question: What is the same and what is different about these lines?

-
-

Activity 3 Answer the following questions

+
+

Activity 3 Answer the following questions

cat ("Q1 In the equation y=mx+c, what happens when you change c?")
 cat ("Q2 What happens when you change m?")
-
-

Activity 4: Work out the equation from a line graph

+
+

Activity 4: Work out the equation from a line graph

Write down the equations of the following four lines on the graph below.

Knit the document to get a good view of the graph.

@@ -722,11 +781,10 @@

Activity 4: Work out the equation from a line graph

-

Representing Data with boxplots

-
-

Lesson objectives

+
+

Lesson objectives

  • To understand how to visualise the shape of data using box plots
  • @@ -736,15 +794,15 @@

    Lesson objectives

-
-

Packages used in this lesson:

+
+

Packages used in this lesson:

  • tidyverse
  • astsa
-
-

Success criteria

+
+

Success criteria

  • Draw a box plot using R code
  • Produce a five number summary using R code
  • @@ -752,8 +810,8 @@

    Success criteria

  • Compare two box plots
-
-

Keywords

+
+

Keywords

box plot, minimum, maximum, lower quartile, median, upper quartile, five number summary, inter-quartile range, range

@@ -857,9 +915,7 @@

Questions

  • The shortest person is a girl

  • The tallest person is a boy

  • Half the boys are over 172 cm tall

  • -
  • Half the girls are under 165cm tall

  • - - +
  • Half the girls are under 165cm tall + + + + - +

    - +
  • +