RCharts scatterChart增强功能

Chr*_*ris 2 r nvd3.js rcharts

我正在尝试将RChart嵌入到闪亮的应用程序中.我特意使用该nPlot函数来创建type=scatterChartNVD3样式图.在下面的NVD3网站示例中,我有兴趣在我的RCharts闪亮应用程序中工作的两个功能:

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

  1. 看起来沿着上述示例的x轴和y轴包括"地毯",略微证明了x和y点沿着它们各自的支撑最频繁出现的位置.
  2. 此外,当一个人点击图表并悬停在特定点上时,会出现一条垂直和水平线,注意到相应点的(x,y)位置.

有谁知道如何扩展我的代码以实现这两个功能.闪亮的server.r和ui.r脚本包含在下面.

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

x <- rnorm(100)
y <- rnorm(100)
dat <- as.data.frame(cbind(x,y))

shinyServer(function(input, output) {

output$myChart <- renderChart({

p1 <- nPlot(y ~ x, data = dat, type = "scatterChart")

p1$addParams(dom = 'myChart')

p1$params$height=400
p1$params$width=650

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: 400px;}"),
showOutput("myChart","Nvd3")
)

)
))
Run Code Online (Sandbox Code Playgroud)

提前感谢您提供的任何建议.

tim*_*lio 6

这可以使用以下代码实现:

p1$chart(
  showDistX = TRUE,
  showDistY = TRUE
)

return(p1)
Run Code Online (Sandbox Code Playgroud)

此外,就像一张纸条,而直接操控p1$params的作品,它可能是更安全的规定height,并width以这种方式:

p1 <- nPlot(
  y ~ x,
  data = dat,
  type = "scatterChart",
  height = 400,
  width = 650
)
Run Code Online (Sandbox Code Playgroud)