Loading Packages
library(ggplot2)
library(dplyr)
library(plotly)
library(reshape2)
library(shiny)
library(readr)
library(lubridate)
library(tidyverse)
library(ggfortify)
library(tseries)
library(forecast)
library(xts)
library(astsa)
library(DT)
library(gapminder)
library(wesanderson)
library(maps)
library(plyr)
Loading data
ggplot2::txhousing
## # A tibble: 8,602 x 9
## city year month sales volume median listings inventory date
## <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Abilene 2000 1 72. 5380000. 71400. 701. 6.30 2000.
## 2 Abilene 2000 2 98. 6505000. 58700. 746. 6.60 2000.
## 3 Abilene 2000 3 130. 9285000. 58100. 784. 6.80 2000.
## 4 Abilene 2000 4 98. 9730000. 68600. 785. 6.90 2000.
## 5 Abilene 2000 5 141. 10590000. 67300. 794. 6.80 2000.
## 6 Abilene 2000 6 156. 13910000. 66900. 780. 6.60 2000.
## 7 Abilene 2000 7 152. 12635000. 73500. 742. 6.20 2000.
## 8 Abilene 2000 8 131. 10710000. 75000. 765. 6.40 2001.
## 9 Abilene 2000 9 104. 7615000. 64500. 771. 6.50 2001.
## 10 Abilene 2000 10 101. 7040000. 59300. 764. 6.60 2001.
## # ... with 8,592 more rows
Visualisaton 1
g <- ggplot(txhousing, aes(x = date, y = sales, group = city)) +
geom_line(alpha = 0.4)
g

Visualisaton 2
g <- txhousing %>%
# group by city
group_by(city) %>%
# initiate a plotly object with date on x and median on y
plot_ly(x = ~date, y = ~median) %>%
# add a line plot for all texan cities
add_lines(name = "Texan Cities", hoverinfo = "none",
type = "scatter", mode = "lines",
line = list(color = 'rgba(192,192,192,0.4)')) %>%
# plot separate lines for Dallas and Houston
add_lines(name = "Houston",
data = filter(txhousing,
city %in% c("Dallas", "Houston")),
hoverinfo = "city",
line = list(color = c("red", "blue")),
color = ~city)
g