sch*_*sie 7 plot r time-series dygraphs
我想使用dygraph一次绘制多个图(它们不必在第一步中同步)
基础R-例子:
temperature <- ts(frequency = 12, start = c(1980, 1),
data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5,
25.2, 26.5, 23.3, 18.3, 13.9, 9.6))
rainfall <- ts(frequency = 12, start = c(1980, 1),
data = c(49.9, 71.5, 106.4, 129.2, 144.0, 176.0,
135.6, 148.5, 216.4, 194.1, 95.6, 54.4))
par(mfrow = c(2, 1))
plot(temperature)
plot(rainfall)
Run Code Online (Sandbox Code Playgroud)
使用dygraph这种方法不起作用
require(dygraphs)
par(mfrow = c(2, 1))
dygraph(temperature)
dygraph(rainfall)
Run Code Online (Sandbox Code Playgroud)
我知道有可能显示第二轴等.但也许有人知道一次显示两个图的答案
要在同一RStudio窗口中绘制多个图表,您必须首先创建一个图表对象列表,然后使用htmltools包呈现该图表列表。RStudio的Yiyi Xie提供了以下答案:
Xiehui Xie答案(但未分组)。
我在这里回答了类似的问题: 我的回答。
这是R
产生分组的(同步的)笔画图的工作代码:
# create the time series
temperature <- ts(frequency = 12, start = c(1980, 1),
data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5,
25.2, 26.5, 23.3, 18.3, 13.9, 9.6))
rainfall <- ts(frequency = 12, start = c(1980, 1),
data = c(49.9, 71.5, 106.4, 129.2, 144.0, 176.0,
135.6, 148.5, 216.4, 194.1, 95.6, 54.4))
# create a list of dygraphs objects
library(dygraphs)
library(htmltools)
dy_graph <- list(
dygraphs::dygraph(temperature, group="temp_rain", main="temperature"),
dygraphs::dygraph(rainfall, group="temp_rain", main="rainfall")
) # end list
# render the dygraphs objects using htmltools
htmltools::browsable(htmltools::tagList(dy_graph))
Run Code Online (Sandbox Code Playgroud)
上面的R
代码生成以下分组(同步)的笔画图: