library(BatchGetSymbols) tickers <- c('AAPL', 'MSFT', 'AMZN', 'GOOG') df_stocks <- BatchGetSymbols(tickers = tickers, first.date = Sys.Date() - 500, last.date = Sys.Date())[[2]] p <- ggplot(df_stocks, aes(x = ref.date, y = price.adjusted, color = ticker)) + geom_line() + labs(title = paste0('Prices for ', tickers) , subtitle = paste0('Data from ', min(df_stocks$ref.date), ' to ', max(df_stocks$ref.date)), caption = "Solution for exercise 04, chapter 10 - afedR") # add points and facet wrap p <- p + geom_point() + facet_wrap(~ticker, scales = 'free') print(p)
# none my_answers <- rep(0, 5)
For the same plot, separate the stock prices on different panels with the ggplot::facet_wrap
function. Use the scales = 'free'
argument to release the x and y axis of each panel.
extype: string
exsolution: r mchoice2string(c(TRUE, FALSE, FALSE, FALSE, FALSE), single = TRUE)
exname: "function 01"
exshuffle: TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.