rChart forceY multiBar" Bar start"在rmarkdown中不正确

时间:2015-04-29 07:29:42

标签: r rcharts

当我在控制台中运行r代码时,我得到了我期望的输出,但是当我在rmarkdown中运行它时,我得到了这个结果:

The bars do not start at my forced y = 0.4

The complete rmarkdown minimum example looks like this:

---
title: "Untitled"
author: "sda"
output: html_document
---


```{r}
library(dplyr)
library(tidyr)
library(rCharts)
library(data.table)
```

```{r results = 'asis', comment = F, message = F, tidy = F, echo=F, cache=F}

myData <- data.table(XAxis = rep(seq(0,length.out = 3),each = 2),
                     Value = c(0.6,0.8,0.4,0.55,0.87,0.42),
                     Type = c("A", "B", "A", "B", "A", "B"))

  #' Create a multiBarChart using nvd3 of rCharts
  plot <- nPlot(Value ~ XAxis, group = 'Type', 
                            data = myData, type = 'multiBarChart')

  plot$chart(forceY = c(0.5, 1))
 plot$show('iframesrc', cdn = TRUE)


```
Look the bars start too low 

所以forceY似乎无法正常工作。有一个简单的解决方法吗?

1 个答案:

答案 0 :(得分:1)

最简单的解决方法是保存绘图并将其显示在iframe中。 您的示例如下所示:

---
title: "Untitled"
author: "sda"
output: html_document
---


```{r}
library(dplyr)
library(tidyr)
library(rCharts)
library(data.table)
```

```{r results = 'asis', comment = F, message = F, tidy = F, echo=F, cache=F}

myData <- data.table(XAxis = rep(seq(0,length.out = 3),each = 2),
                     Value = c(0.6,0.8,0.4,0.55,0.87,0.42),
                     Type = c("A", "B", "A", "B", "A", "B"))


  plot <- nPlot(Value ~ XAxis, group = 'Type', 
                            data = myData, type = 'multiBarChart')

plot$chart(yDomain = c(0.5, 1))
plot$save("plot.html", standalone = TRUE)


```

<iframe src="plot.html" height="500" width="900" frameBorder="0"></iframe>

请注意,我使用的是yDomain而不是forceY。我这样做是因为forceY在我的电脑中显示了y = 0.4的图表。但是,图表也会使用forceY正确显示。

您可以在此处找到我对此解决方案的想法的讨论:https://github.com/ramnathv/rCharts/issues/373