【发布时间】:2015-03-13 10:18:21
【问题描述】:
我想用 rCharts 包显示两个图表,一个并排,或多或少像此链接中显示的两个饼图:
http://nvd3.org/examples/pie.html
我有一个使用<iframe>的部分解决方案,但是该解决方案存在三个问题:
- 过于具体
- 包含控件成为一项复杂的任务
- 看起来不太好看
最小工作示例:
---
title: "Example"
output: html_document
---
```{r rcht, message=FALSE, echo=FALSE, results='asis'}
library(rCharts)
df<-data.frame(label=c("One","Two","Three"),valuea=c(1,2,3),othera=c(10,11,12),
valueb=c(4,5,6),otherb=c(10,11,12),stringsAsFactors = FALSE)
p1 <- nPlot(valuea~ label, data = df, type = 'pieChart',height = 225, width = 300)
p2<- nPlot(valueb~ label, data = df, type = 'pieChart',height = 225, width = 300)
p1$show('inline', include_assets = TRUE, cdn = F)
p2$show('inline', include_assets = TRUE, cdn = F)
```
```{r message=FALSE, echo=FALSE}
p1$save("pie1.html", standalone = TRUE)
p2$save("pie2.html", standalone = TRUE)
```
<div align="center">
<font size="10" color="black" face="sans-serif">Both Pies</font><br>
<p>
<iframe src="pie1.html" height="400" width="400"></iframe>
<iframe src="pie2.html" height="400" width="400"></iframe>
</p>
<div>
我知道不应使用饼图,我可以使用多条形图。但是,我想在 rCharts 包中将这种类型的布局与其他类型的图表一起使用。
此外,我想在图表中包含控件,同时它们彼此相邻显示。在$save()函数添加控件之前包括以下代码:
```{r message=FALSE, echo=FALSE}
p1$addControls('y','valuea',values=c('valuea','othera'))
p2$addControls('y','valueb',values=c('valueb','otherb'))
```
这个问题与我无关,但如果有人有解决方案(最好两个图表都只有一个控件),那就太好了。
我知道 R 可能无法处理所有这些问题。感谢您提供任何帮助/建议。
【问题讨论】:
标签: r nvd3.js r-markdown rcharts