Line Plots
There are many variables that change over time. Line plots are useful in visualizing data points across time.
library(datasets)
library(ggplot2)
library(ggthemr)
# Converting the data to time series
data = as.data.frame(AirPassengers)
data$months = seq(as.Date("1949-01-01"), by = "month", length.out = nrow(data))
colnames(data) <- c("passengers", "months")
head(data)
passengers | months | |
---|---|---|
<dbl> | <date> | |
1 | 112 | 1949-01-01 |
2 | 118 | 1949-02-01 |
3 | 132 | 1949-03-01 |
4 | 129 | 1949-04-01 |
5 | 121 | 1949-05-01 |
6 | 135 | 1949-06-01 |
ggthemr('grape')
base = ggplot(data = data, aes( x = months , y = passengers)) +
geom_line() +
labs( title = "Airline Passengers by Month")
base