From Wikipedia and R-project website, ``ggplot2 is a data visualization package for the statistical programming language R. Created by Hadley Wickham in 2005, ggplot2 is an implementation of Leland Wilkinson’s Gurky Gang—a general scheme for data visualization which breaks up graphs into semantic components such as scales and layers. ggplot2 can serve as a replacement for the base graphics in R and contains a number of defaults for web and print display of common scales. Since 2005, ggplot2 has grown in use to become one of the most popular R packages.”
It is a general framework for data visualisation, and in this class, we will use it to visualise spatial data and spatio-temporal data.
library(tidyverse)
An Example
f = lm(hwy~displ, data = mpg)
ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point()
Add one more layer (the line)
ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(color = "blue") +
geom_abline(slope = f$coef[2], intercept = f$coef[1])
with different colors
mpg$cyl = factor(mpg$cyl)
ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(aes(color = cyl, shape = cyl)) +
geom_abline(slope = f$coef[2], intercept = f$coef[1])
Visualize the daily pattern of mel_sel data.