【问题标题】:RCharts lineChart FeaturesRCharts lineChart 功能
【发布时间】:2013-10-05 19:16:05
【问题描述】:

我正在尝试将 RChart 嵌入到闪亮的应用程序中。具体来说,使用函数nPlottype=lineChart NVD3 特性。我正在尝试为模拟的 Normal 数据绘制 3 条密度曲线。我正在尝试实现以下示例中描述的一些功能:

http://nvd3.org/ghpages/line.html

我的问题:

  1. 如何为不同的密度曲线设置不同的颜色?
  2. 如何具有单击组变量 (1)、(2)、(3) 的功能以有效删除选定的密度。类似于点击示例中的“Sine Wave”(右上角)来移除橙色的正弦曲线?
  3. 如何添加x轴和y轴标签?我的$params$xAxis= 电话打不通。

下面是我的 server.R 和 ui.R 文件:

## server.r
library(rCharts)
library(shiny)

x <-rnorm(1000,0,1)
y <-rnorm(1000,1,1)
z <-rnorm(1000,2,1)
out <- c(x,y,z)
grp <- c(rep(0,1000),rep(1,1000),rep(2,1000))
data <- as.data.frame(cbind(out,grp))
dens <- by(data$out, data$grp, density)
d <- unlist(c(dens[[1]][1][1], dens[[2]][1][1], dens[[3]][1][1]))
support <- unlist(c(dens[[1]][2][1], dens[[2]][2][1], dens[[3]][2][1]))
grpvar <- c(rep(0,length(unlist(dens[[1]][1][1]))), rep(1,length(unlist(dens[[2]][1][1]))), rep(2,length(unlist(dens[[3]][1][1]))))
dat <- as.data.frame(cbind(d,support,grpvar))


shinyServer(function(input, output) {

output$myChart <- renderChart({

p1 <- nPlot(support~d, group=grpvar, data = dat, type = "lineChart")

p1$addParams(dom = 'myChart')
p1$params$width = 600
p1$params$height = 400

p1$params$xAxis = "Support"
p1$params$yAxis = "Density"

p1$chart(tooltipContent = "#! function(key, x, y, e){
return '<b>Group</b>: ' + e.point.grpvar
} !#")

return(p1)
})
})


## ui.R
library(rCharts)
library(shiny)

shinyUI(pageWithSidebar(
headerPanel("rCharts: Interactive Charts from R using NVD3.js"),

sidebarPanel(

wellPanel(
    helpText(   "Look at the pretty graph"
    )
    ),

wellPanel(
    helpText(   "Look at the pretty graph"
    )
    ),

wellPanel(
    helpText(   "Look at the pretty graph"
    )
    )

),


mainPanel(
div(class='wrapper',
tags$style(".Nvd3{ height: 600px;}"),
showOutput("myChart","Nvd3")
)

)
))

提前感谢您提供的任何帮助/建议。

【问题讨论】:

    标签: r nvd3.js rcharts


    【解决方案1】:

    您只需要在grpvar 周围添加引号,所以

    p1 <- nPlot(support~d, group="grpvar", data = dat, type = "lineChart")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-27
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      相关资源
      最近更新 更多