4/26/2020

Requirements

-Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities.

-Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly. We would love to see you show off your creativity!

Time Series Chart in R

library(plotly)
now_lt<-as.POSIXct(Sys.time(), tz="GMT")
tm<-seq(0, 500, by=10)
x<-now_lt-tm
y<-rnorm(length(x))

fig1<-plot_ly(x=~x, y=~y, mode="lines", 
              text=paste(tm, "seconds from now in GMT"))

Time Series Chart in R

Basic Candlestick Chart in R

library(plotly)
library(quantmod)
getSymbols("BK",src='yahoo')
## [1] "BK"
df <- data.frame(Date=index(BK),coredata(BK))
df <- tail(df, 30)

fig2 <- df %>% plot_ly(x = ~Date, type="candlestick",
          open = ~BK.Open, close = ~BK.Close,
          high = ~BK.High, low = ~BK.Low) 
fig2 <- fig2 %>% layout(title = "Basic Candlestick Chart in R",
                        xaxis=list(rangeslider=list(visible=F)))

Basic Candlestick Chart in R

Bar Chart in R

for (i in 1:length(df[,1])) {
  if (df$BK.Close[i] >= df$BK.Open[i]) {
      df$direction[i] = 'Increasing'
  } else {
      df$direction[i] = 'Decreasing'
  }
}
i <- list(line = list(color = '#17BECF'))
d <- list(line = list(color = '#7F7F7F'))

fig3<-df
fig3<-fig3%>%plot_ly(x=~Date, y=~BK.Volume, type="bar", name="BK Volume",
                     color=~direction, colors = c('#17BECF','#7F7F7F'))
fig3<-fig3%>%layout(yaxis=list(title="Volmue"))

Bar Chart in R