RCharts 散点图增强功能

标签 r nvd3.js rcharts

我正在尝试将 RChart 嵌入到 Shiny 的应用程序中。我专门使用 nPlot 函数来创建 type=scatterChart NVD3 样式图。在下面的 NVD3 网站示例中,我有兴趣在我的 RCharts Shiny 应用程序中使用两个功能:

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

  1. 似乎在上述示例的 x 轴和 y 轴上包含了一个“地毯”,略微展示了 x 点和 y 点在其各自支撑点上最常出现的位置。
  2. 此外,当点击图表并将鼠标悬停在特定点上时,会出现一条垂直线和水平线,标明相应点的 (x,y) 位置。

有谁知道如何扩展我下面的代码来实现这两个功能。下面包含 Shiny 的 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")
)

)
))

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

最佳答案

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

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

return(p1)

此外,请注意,虽然直接操作 p1$params 有效,但在中指定 heightwidth 可能更安全这样:

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

关于RCharts 散点图增强功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19085351/

相关文章:

c++ - rcpp包创建符号找不到错误

r - 如何在 R 中检查文件的魔数(Magic Number)(或十六进制签名)?

d3.js - 具有域外日期间隔的 LinePlusBarChart

r - 在 rCharts + polychart 中手动设置点颜色

从 ggplot 中删除 y 标签

r - 在现有 geom_sf 图层下方插入 geom_sf 图层

d3.js - NVD3.js:具有两个 y 轴的堆叠和分组条形图

javascript - 如何在 Angular-js 中旋转柱形图上的 x 轴标签?

r - 通过 rCharts 格式化 Highcharts 图

r - 使用 rCharts 为图表中的所有数据点添加唯一链接