The data used for this dynamic figure is stock market data from the start of 2006 to the end of 2018. The dataset is on Kaggle and can be found at https://www.kaggle.com/datasets/szrlee/stock-time-series-20050101-to-20171231?resource=download. The dataset consists of data for thirty different stocks and I chose to use a subset of five stocks including Home Depot, Apple, Microsoft, Walmart and McDonalds and shortened the time to the start of 2015 and ending at the end of 2018. This made the figures easier to read and interact with. Variables include date, open, close, high and low price for each day along with the volume.
stocks = read.csv("Data/all_stocks_2006-01-01_to_2018-01-01.csv")
stocks = stocks %>%
mutate(Date = as.Date(Date)) %>%
filter(Name == c("HD", "AAPL", "MSFT", "WMT", "MCD")) %>%
filter(Date >= "2015-01-01")
head(stocks)
## Date Open High Low Close Volume Name
## 1 2015-01-06 106.54 107.43 104.63 106.26 65797116 AAPL
## 2 2015-01-13 111.43 112.80 108.91 110.22 67091928 AAPL
## 3 2015-01-21 108.95 111.06 108.27 109.55 48575897 AAPL
## 4 2015-01-28 117.62 118.12 115.31 115.31 146477063 AAPL
## 5 2015-02-04 118.50 120.51 118.31 119.56 70149743 AAPL
## 6 2015-02-11 122.77 124.92 122.50 124.88 73561797 AAPL
stocks_plot = ggplot(data = stocks, aes(x=Date, y = Close, color = Name)) +
geom_line() +
theme_minimal() +
scale_x_date(breaks = "1 year",
minor_breaks = "1 month",
date_labels = "%Y",
limits=c(as.Date("2015-01-01"), NA)) +
ylab("Price") + xlab("") +
ggtitle("Price for Several Large Companies") +
scale_color_viridis(discrete = TRUE) +
guides(color=guide_legend(title="Ticker"))
volume_plot = ggplot(data = stocks, aes(x=Date, y = Volume/1000000, color = Name)) +
geom_line() +
theme_minimal() +
scale_x_date(breaks = "1 year",
minor_breaks = "1 month",
date_labels = "%Y",
limits=c(as.Date("2015-01-01"), NA)) +
ylab("Volume (in millions)") + xlab("") +
ggtitle("Volume for Several Large Companies") +
scale_color_viridis(discrete = TRUE) +
guides(color=guide_legend(title="Ticker"))
stocks_plotly = ggplotly(stocks_plot)
volume_plotly = ggplotly(volume_plot)
stocks_plotly
In this first figure, I wanted to convey the rise of these stock prices over three years. This figure is meant to be simple and clearly show the price movement for the five selected companies. Only the date, price and company name are displayed for each point and the ability to display or remove companies allow for easy access to a specific company.
volume_plotly
Very similar to the price figure, this plot is meant to convey the volumes for the same five companies over a time frame of three years. Volume can sometimes be an indicator of large price movements in stocks so showing volume spikes can be interesting. Like above, the formatting and functionality are simple and clean but demonstrate the volume movements effectively with labeled data points.
stocks_plty_facet <- subplot(list(stocks_plotly,volume_plotly),
nrows = 2,
shareX = TRUE,
titleX = FALSE) %>%
rangeslider() %>%
layout(hovermode = "x")
stocks_plty_facet