rcharts NVD3线形图中的绘图区域

rcharts NVD3线形图中的绘图区域,r,nvd3.js,area,linechart,rcharts,R,Nvd3.js,Area,Linechart,Rcharts,我想用rCharts的NVD3线形图绘制不同人群的分布,使用area=true选项,如中所示 以下是我的工作: require(devtools) install_github('ramnathv/rCharts') require(rCharts) df<-data.frame(X=rep(1:4,2),Y=1:8,fil=c(rep("A",4),rep("B",4))) denp <- nPlot(Y ~ X, group = 'fil', data = df, type

我想用rCharts的NVD3线形图绘制不同人群的分布,使用area=true选项,如中所示

以下是我的工作:

require(devtools)
install_github('ramnathv/rCharts')
require(rCharts)

df<-data.frame(X=rep(1:4,2),Y=1:8,fil=c(rep("A",4),rep("B",4)))

denp <- nPlot(Y ~ X, group = 'fil', data = df, type = 'lineChart')
denp$chart(color =c('#ff7f0e', 'blue', 'green'))
denp$yAxis(axisLabel= 'Density')
denp$xAxis(axisLabel= 'Value')
denp$chart(margin = list(left=80,bottom=80))
denp$yAxis(tickFormat = "#!function (x,y,e) { return }!#")
denp$xAxis(tickFormat = "#!function (x,y,e) { 
tickformat = ['0,01','0,1',1,10,100,1000,10000,'100k'];
return tickformat[x+2];}!#")
denp$chart(tooltipContent = "#! function(key, val, e, graph){
return '<h3>' + '<font color=blue>'+ key +'</font>'+ '</h3>' + '<p>'+ val } !#")

denp
所有这些结果都是一个空白图。
有没有办法从rCharts内部使用此类型图形的区域选项,或者它目前超出了库的范围?

将类型更改为
'stackedAreaChart'

这就是你想要的吗

denp <- nPlot(Y ~ X, group = 'fil', data = df, type = 'stackedAreaChart')
denp$chart(color =c('#ff7f0e', 'blue', 'green'))
denp$yAxis(axisLabel= 'Density')
denp$xAxis(axisLabel= 'Value')
denp$chart(margin = list(left=80,bottom=80))
denp$yAxis(tickFormat = "#!function (x,y,e) { return }!#")
denp$xAxis(tickFormat = "#!function (x,y,e) { 
tickformat = ['0,01','0,1',1,10,100,1000,10000,'100k'];
return tickformat[x+2];}!#")
denp$chart(tooltipContent = "#! function(key, val, e, graph){
return '<h3>' + '<font color=blue>'+ key +'</font>'+ '</h3>' + '<p>'+ val } !#")

denp

denp这大概就是你要找的吗

我通过添加行来实现这一点

denp$chart(isArea=TRUE)

到您的代码。看起来将区域布尔值设置为true的函数名为isrea()。

您可以使用@seaotternerd建议的
isrea
函数,并使用自定义javascript函数专门设置要设置为true的区域参数

例如,使用:

denp$chart(isArea="#! function(d) {
           if(d.key=='A') return true;
           } !#")
这里
d
是数据

你会得到:


我要找的是一个折线图,其中一条线的区域已填充,而另一条线的区域未填充。”stackedAreaChart'用于堆叠时间序列,即按时间段销售产品,当需要两个y轴(即价格和销售)时,使用“multiChart”。在我的例子中,我希望两条线的y轴相同,我不需要在另一条线上加上数量,它更接近我想要的。但是,我希望其中一个组是一个区域,另一个组是一条线。我无法根据团队的不同将isArea设置为TRUE或FALSE。这就是我一直在寻找的。塔恩克斯,我不确定我是否能用isArea的函数。
denp$chart(isArea="#! function(d) {
           if(d.key=='A') return true;
           } !#")