【问题标题】:Setting rChart width and height设置 rChart 宽度和高度
【发布时间】:2013-10-22 23:45:37
【问题描述】:

在网络上(目前很少)集成 knitr 和 rCharts 的面向学习的示例中,我们经常在 R 块中看到一行代码,如下所示:

options(RCHART_WIDTH = 800, RCHART_HEIGHT = 500)

当我在 R 降价文档的 R 块中包含这种变量设置时,它似乎对 html 中最终图表的实际大小没有任何影响。我缺少什么额外的东西可以让我控制 rCharts 的宽度和高度?可重现的 *.rmd 文件如下。

```{r echo = F, message = F, cache = F}
opts_chunk$set(results = 'asis', comment = NA, message = F, tidy = F, echo=FALSE, cache=FALSE)
require(rCharts)
options(RCHART_WIDTH = 600, RCHART_HEIGHT = 400)
```

## Example plot with un-customised dimensions
```{r}
data(economics, package = 'ggplot2')
econ <- transform(economics, date = as.character(date))
m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',
            data = econ)
m1$set(pointSize = 0, lineWidth = 1)
m1$print('chart2', include_assets = TRUE, cdn=TRUE)
```

【问题讨论】:

  • 问题是print 方法不包括调整图表大小的css。最简单的解决方法是将以下 css 添加到您的 Rmd 文件 &lt;style&gt;.rChart{width: 600px; height: 400px}&lt;/style&gt;。 print 方法正在重写,我们正在尝试找出最灵活但最有用的方法。
  • 感谢@Ramnath,这很好,解释也很有意义。如果您想发布它,我会接受它作为答案。

标签: r knitr rcharts


【解决方案1】:

问题是打印方法不包括调整图表大小的 css。最简单的解决方法是将以下 css 添加到您的 Rmd 文件 .rChart{width: 600px;高度:400px}。正在重写 print 方法,我们正在尝试找出最灵活但最有用的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 2011-08-17
    相关资源
    最近更新 更多