一次在多个R图中的笔画 [英] dygraph in R multiple plots at once

查看:115
本文介绍了一次在多个R图中的笔画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用dygraph一次绘制多个图(不必在第一步中进行同步)

I want to plot multiple plots at once using dygraph (they do not have to be synchronized in the first step)

基本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)

使用dygraph时,此方法不起作用

With dygraph this approach does not work

require(dygraphs)
par(mfrow = c(2, 1))
dygraph(temperature)
dygraph(rainfall)

我知道有可能显示第二个坐标轴等.但是也许有人知道一次显示两个图的答案

I know there's the possibility to display second axis etc. But maybe someone knows an answer to displaying both plots at once

推荐答案

要在同一RStudio窗口中绘制多个笔形图,您必须首先创建笔形图对象的列表,然后使用包 htmltools 呈现 dygraphs 列表. RStudio的谢逸辉(Yihui Xie)在这里提供了答案: 谢逸辉答案(但没有分组).
我在这里回答了类似的问题:我的回答.

To plot multiple dygraphs in the same RStudio window you must first create a list of dygraphs objects, and then render the dygraphs list using package htmltools. Yihui Xie from RStudio provided the answer here: Yihui Xie answer (but without grouping).
I answered a similar question here: my answer.

这里正在工作的R代码会生成分组的(同步的)笔形图图:

Here is working R code that produces grouped (synchronized) dygraphs plots:

# 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))

上面的R代码生成了以下分组的(同步的)笔形图图:

The above R code produces the following grouped (synchronized) dygraphs plots:

这篇关于一次在多个R图中的笔画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆