Equations of Straight Line Graphs - Part 1

This lesson is part 1 of 2 and demonstrates how to use R to plot straight line graphs (y=mx+c) and to observe what happens when the value of m changes

Download .Rmd here

Download word document here

Download pdf here

KS3: Drawing and finding the equations of straight line graphs (y=mx+c)

Lesson objectives

Plotting straight line graphs y=mx+c

Packages used in this lesson:

Success criteria

Keywords

Remember

Knit your document often to check the output.

Make sure you do a final knit at the end of the lesson

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.

Run the code by clicking on the little arrow to the right of the code chunk.

x <- seq(from=-4, to=4, by=1) # sequence the x-axis from -4 to 4
y <- 2*x+5
mydata <- tibble (x,y)
ggplot(mydata) +
  aes(x,y) +
  geom_line (col='red')+
  geom_vline (xintercept = 0, col='black')+
  geom_hline (yintercept = 0, col='black')

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

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)

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
x <- seq(-4, 4) # sequence from -4 to 4
y1 <- 3*x+0
y2 <- 3*x+1
y3 <- 3*x+2
y4 <- 3*x+3
mydata <- tibble (x,y1,y2,y3,y4)
ggplot(mydata) +
  geom_line (aes(x=x, y=y1), col='red')+
  geom_line (aes(x=x, y=y2), col='blue')+
  geom_line (aes(x=x, y=y3), col='green')+
  geom_line (aes(x=x, y=y4), col='grey') +
  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?

Answer:

Activity2:

Draw the following lines on a graph

  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.

Run the code. Knit the document.

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

Answer:

KNIT YOUR DOCUMENT for the final time. This will be the version that your teacher marks.

THE END

License and Citation: You can use, modify, and adapt any of the lessons, but please include the following attribution: RGirls Community. (2022, April 10). RGirls Lessons. Zenodo. https://doi.org/10.5281/zenodo.6436861