RChart を光沢のあるアプリに埋め込もうとしています。具体的には、関数nPlot
とtype=lineChart
NVD3 機能を操作します。シミュレートされた法線データの 3 つの密度曲線をプロットしようとしています。以下の例で説明されている機能の一部を実現しようとしています。
http://nvd3.org/ghpages/line.html
私の問題:
- 密度曲線ごとに異なる色を使用するにはどうすればよいですか?
- グループ変数 (1)、(2)、(3) をクリックして、選択した密度を効果的に削除する機能を持たせる方法。例の「Sine Wave」(右上) をクリックして、オレンジ色の正弦曲線を削除するのと同じようなことですか?
- 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")
)
)
))
あなたが提供できる助け/アドバイスを前もって感謝します。