if (FALSE) {
## de Carvalho et al (2022; Fig 5.1)
data(marketsUS)
packages <- c("ggplot2", "scales")
sapply(packages, require, character.only = TRUE)
ggplot(data = marketsUS, aes(x = date, y = value, color = Indices)) +
geom_line(aes(y = nasdaq, col = "NASDAQ"), alpha = 0.5,
position = position_dodge(0.8), size = 1.1) +
geom_line(aes(y = nyse, col = "NYSE"), alpha = 0.5,
position = position_dodge(0.8), size = 1.1) +
scale_y_continuous(breaks = seq(2000, 14000, by = 2000)) +
scale_x_date(labels = date_format("%Y"),
breaks = as.Date(c("1971-01-01", "1978-01-01",
"1985-01-01", "1992-01-01",
"1999-01-01", "2006-01-01",
"2013-01-01", "2020-01-01"))) +
scale_color_manual(values = c("red", "blue")) +
labs(y = "Value (in USD)", x = "Time (in Years)") +
theme_minimal()
}
Run the code above in your browser using DataLab