Jon*_*gra 10 r linechart area nvd3.js rcharts
我想用rCharts的NVD3 lineChart图使用area = true选项绘制不同种群的分布,如http://nvd3.org/examples/line.html.
我在这里工作:
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
Run Code Online (Sandbox Code Playgroud)
我发现的问题是我无法将area参数切换为true.我试过了:
denp$chart(area=TRUE)
denp$chart(area=c(TRUE,TRUE,TRUE))
denp$chart(area=c('true'))
denp$chart(area=c('true','true','true'))
denp$chart(area=c('#!true!#'))
denp$chart(area=c('#!true!#','#!true!#','#!true!#'))
Run Code Online (Sandbox Code Playgroud)
所有这些结果都是一个空白的情节.有没有办法在rCharts中使用此类图表的区域选项,还是目前超出图书馆的范围?
您可以按照 @seotternerd 建议使用该isArea函数,并使用自定义 JavaScript 函数来专门设置要设置为 true 的区域参数。
例如,使用:
denp$chart(isArea="#! function(d) {
if(d.key=='A') return true;
} !#")
Run Code Online (Sandbox Code Playgroud)
这d是数据。
你得到:
