我一直试图在一个图中绘制4个烛台图。 grid.arrange,layout或par()函数不起作用。我也尝试了以下代码
m1 <- tail(merck.xts, n = 32)
head(merck.xts)
Open High Low Close Adj.Close
2019-09-04 "87.14" "87.17" "85.420" "86.05" "83.54009"
2019-09-05 "86.64" "86.66" "85.500" "86.10" "83.58862"
2019-09-06 "86.54" "86.93" "86.310" "86.57" "84.04491"
2019-09-09 "86.50" "86.52" "82.920" "83.47" "81.03533"
2019-09-10 "82.39" "82.39" "78.850" "81.69" "79.30725"
2019-09-11 "81.86" "83.11" "81.620" "82.92" "80.50137"
dy_graph <- list(
dygraphs::dygraph(m1, group="Indicator", main="Merck"),
dygraphs::dygraph(m2, group="indicator", main="Pfizer")
)
dy_candlestick<-dyCandlestick(dy_graph)
htmltools::browsable(htmltools::tagList(dy_candlestick))
此代码的问题在于,它可以将2个图表合并到一个图中,但没有显示烛台
还有两个烛台图表,以及m3和m4。如果有人可以回答,那将非常有用。预先感谢
答案 0 :(得分:0)
您的时间序列矩阵对我来说很奇怪。似乎是所有角色。您可以通过使用示例数据集来使其工作,注意并检查您是否具有数字字符而不是字符:
library(dygraphs)
library(htmltools)
data(sample_matrix)
m1 <- head(sample_matrix, n = 32)
m2 <- tail(sample_matrix, n = 32)
# you can see it's num
str(m1)
num [1:32, 1:4] 50 50.2 50.4 50.4 50.2 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:32] "2007-01-02" "2007-01-03" "2007-01-04" "2007-01-05" ...
..$ : chr [1:4] "Open" "High" "Low" "Close"
str(m2)
num [1:32, 1:4] 47.8 47.8 47.7 47.6 47.7 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:32] "2007-05-30" "2007-05-31" "2007-06-01" "2007-06-02" ...
..$ : chr [1:4] "Open" "High" "Low" "Close"
dy <-lapply(list(m1,m2),function(i)dygraph(i) %>%dyCandlestick)
browsable(tagList(dy))