Hands-on Exercise 1: A Layered Grammar of Graphics: ggplot2 methods
Author
Zou Jiaxun
Published
April 13, 2024
1 Learning Outcome
In this chapter, we will learn the basic principles and essential components of ggplot2. At the same time, we will gain hands-on experience on using these components to plot statistical graphics based on the principle of Layered Grammar of Graphics. By then end of this chapter we will be able to apply the essential graphical elements provided by ggplot2 to create elegant and yet functional statistical graphic
The code chunk below uses p-load() of pacman package to check if tidyverse packages are installed in the computer. If they are, then they will be launched into R.
Click to view code
pacman::p_load(tidyverse)
The code chunk below imports exam_data.csv into R environment by using read_csv()function of readr package.
readr is one of the tidyverse package.
Click to view code
exam_data <-read_csv("data/Exam_data.csv")
Year end examination grades of a cohort of primary 3 students from a local school.
There are a total of seven attributes. Four of them are categorical data type and the other three are in continuous data type.
The categorical attributes are: ID, CLASS, GENDER and RACE.
The continuous attributes are: MATHS, ENGLISH and SCIENCE.