These exercises cover the sections of Plotting in R PlottingInR.

Exercise 1

Please load the dateset mtcars by calling data(mtcars) and use the base R graphics to

  1. create a scatter plot of mtcars$mpg VS mtcars$wt (x-axis = mpg and y-axis = wt).

  2. change the axis labels to x axis = “Miles/(US) gallon” and y axis = “Weight (1000 lbs)”

  3. add title = “scatter plot”

  4. change the colour of data points to red and the the shape of points to “filled circle”

[hint: use data() function to load mtcars]

data(mtcars)
head(mtcars)

Exercise 2

Please load the dateset mtcars by calling data(mtcars) and use ggplot2 to

  1. create a scatter plot of mtcars$mpg VS mtcars$wt (x-axis = mpg` and y-axis = wt).

  2. change the axis labels to x axis = “Miles/(US) gallon” and y axis = “Weight (1000 lbs)”

  3. add title = “scatter plot”

  4. change the colour of data points to red [hint: use col="red" when constructing aesthetic mappings]

    1. what will happen if change the colour of points to mtcars$am [hint: use col=am when constructing aesthetic mappings]

    2. what will happen if change the colour of points use col=as.factor(am) when constructing aesthetic mappings