@デビッドクルックで
「
royr2 4月25日には、ここで簡単な例を示します。
library(plotly)
library(quantmod)
prices <- getSymbols("MSFT", auto.assign = F)
prices <- prices[index(prices) >= "2016-01-01"]
# Make dataframe
prices <- data.frame(time = index(prices),
open = as.numeric(prices[,1]),
high = as.numeric(prices[,2]),
low = as.numeric(prices[,3]),
close = as.numeric(prices[,4]))
# Blank plot
p <- plot_ly()
# Add high/low as a line segment
# Add open close as a separate segment
for(i in 1:nrow(prices)){
p <- add_trace(p, data = prices[i,], x = c(time, time), y = c(high, low), mode = "lines", evaluate = T,
showlegend = F,
marker = list(color = "grey"),
line = list(width = 1))
p <- add_trace(p, data = prices[i,], x = c(time, time), y = c(open, close), mode = "lines", evaluate = T,
showlegend = F,
marker = list(color = "#ff5050"),
line = list(width = 5))
}
p
UPDATE:
library(plotly)
library(quantmod)
prices <- getSymbols("MSFT", auto.assign = F)
prices <- prices[index(prices) >= "2016-01-01"]
# Make dataframe
prices <- data.frame(time = index(prices),
open = as.numeric(prices[,1]),
high = as.numeric(prices[,2]),
low = as.numeric(prices[,3]),
close = as.numeric(prices[,4]))
plot_ly(prices, x = ~time, xend = ~time, showlegend = F) %>%
add_segments(y = ~low, yend = ~high, line = list(color = "gray")) %>%
add_segments(y = ~open, yend = ~close,
color = ~close > open,
colors = c("#00b386","#ff6666"),
line = list(width = 3))
こちらをご覧くださいより完全な例: plotly 4.0
はこれを行うのリリースでは、多くの方が簡単です近いが開い下回っている場合はどうなりhttp://moderndata.plot.ly/candlestick-charts-using-plotly-and-quantmod/
?次に、 "lower"を "upper"より高い値に設定します。 – user1357015
これらのケースをフィルタリングして無駄にしました。 msft = read.csv( "http://ichart.finance.yahoo.com/table.csv?s=MSFT"、 header = TRUE、 sep = "、") msft $日付 msftF = msft%> % tbl_df()%>% フィルタ(as.Date(Date)> as.Date( "2016-01-01"))%>% フィルタ(閉じる>開く)%>% na.omit X = msftF%>% ggplot(AES(X =因子(日)、YMIN =低、低級= OPEN、CLOSE =中間、閉じる=上側、YMAX =高))+ geom_boxplot()+ geom_boxplot(STAT = "identity") ggplotly(x) –
私は基本的にローソク足チャートを作成しようとしていますが、金融ラッパーはまだRのために存在しないようです。 –