rChart forceY multiBar "Bar start" 在 rmarkdown 中不正确
rChart forceY multiBar "Bar start" not correct in rmarkdown
当我在控制台中 运行 r 代码时,我得到了预期的输出,但是当我在 rmarkdown 中 运行 时,我得到了这个结果:
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似乎没有正常工作。有没有简单的解决方法?
最简单的解决方法是保存绘图并将其显示在 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
当我在控制台中 运行 r 代码时,我得到了预期的输出,但是当我在 rmarkdown 中 运行 时,我得到了这个结果:
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似乎没有正常工作。有没有简单的解决方法?
最简单的解决方法是保存绘图并将其显示在 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