首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RCharts scatterChart增强特征

RCharts scatterChart增强特征
EN

Stack Overflow用户
提问于 2013-09-30 01:51:08
回答 1查看 519关注 0票数 2

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

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

  1. 在上面的例子中,沿着x轴和y轴似乎包含了一个“地毯”,略微显示了x点和y点在它们各自的支座上最频繁出现的位置。
  2. 此外,当你点击图表并在一个特定的点上盘旋时,就会出现一条垂直和水平线,指出对应点的(x,y)位置。

有人知道如何展开下面的代码来实现这两项功能吗?下面包含了闪亮的server.r和ui.r脚本。

代码语言:javascript
复制
## 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")
)

)
))

谢谢你能提供的任何建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-30 02:41:27

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

代码语言:javascript
复制
p1$chart(
  showDistX = TRUE,
  showDistY = TRUE
)

return(p1)

另外,请注意,虽然p1$params的直接操作是有效的,但以这种方式指定heightwidth可能更安全:

代码语言:javascript
复制
p1 <- nPlot(
  y ~ x,
  data = dat,
  type = "scatterChart",
  height = 400,
  width = 650
)
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19085351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档