• R pacaghes needed in this section
library(gghighlight)
library(ggplot2) # {tidyverse} includes {ggplot2}
library(ggrepel)
library(magrittr)# {tidyverse} includes {magrittr}
library(patchwork)
library(plotly)
library(reactable)

1. Drawing a graph on R

  • The most basic syntax of R is called “base R.”
  • The {ggplot2} is a package included in a packaged called the {tidyverse}.
  • Two ways of drawing a graph on R
1. Base R The most basic syntax of R
2. ggplot2 Draw a graph by adding layers
  • Examples of drawing a graph on base R and {ggplot2}

  • You can draw a graph either on base R or on {ggplot2}
  • But, drawring a graph on{ggplot2} is way convenient

2. What is {ggplot2}?

  • An R package made by Hadley Wickham for data visualization
  • ggplot: the grammer of graphics
  • Hadley Wickham distributes {ggplot2} for free

2.1 Two core features on {ggplot2}

1. {ggplot2} implements a graphical grammar proposed by Wilkinson, L. (2005)
2. {ggplot2} has multiple functions corresponding to structural elements of a graph, which work like a layer

2.2 Advantages of using {ggplot2}

  1. R code is easier to read and neat
  2. Easy to change a graphical outlook
  3. Reproducibility of a graph is guranteed
  4. You can write R code based on graphical grammar
  5. Graphical components works as layers
  6. Superior as a tool for an academic explorataion
  7. Abundant R pachages
  8. Abndant {ggplot2} communities

2.3 Preparing {ggplot2}

  • You need to install and read {tidyverse} to start using {ggplot2} on Rmd file
  • The {tidyverse} is a family of packages, including {ggplott2}, {dplyr}, {tidyr}, {readr}, {purrr}, {tibble} and a few others which are useful for data manipuration and data visualization 
  • The {tidyverse} is in continuing development, meaning that some of the fuctions are subject to change though many of the core functions are fairly unchaged.
  • If you encounter difficulties getting your R code to run, it may be because of the {tidyverse} has changed.
  • If this is the case, then you can look up documentation about the package to learn how to update your code.