- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 rCharts 中创建了一个桑基图,但有一个问题。如何添加颜色?我想用不同的颜色表示每个节点,这样更容易可视化路径,而不是仅仅看到连接所有内容的相同灰线。代码和输出如下:
require(rCharts)
require(rjson)
x = read.csv('/Users/<username>/sankey.csv', header=FALSE)
colnames(x) <- c("source", "target", "value")
sankeyPlot <- rCharts$new()
sankeyPlot$set(
data = x,
nodeWidth = 15,
nodePadding = 10,
layout = 32,
width = 500,
height = 300,
units = "TWh",
title = "Sankey Diagram"
)
sankeyPlot$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey')
sankeyPlot
这是我的图表的样子
非常感谢!
最佳答案
不确定您想要什么颜色,但如果您安装了较新的 rCharts
与 devtools::install_github("ramnathv/rCharts")
,以下是您如何根据源值使用 demo here 进行着色。 .
require(rCharts)
require(rjson)
x = read.csv('/Users/<username>/sankey.csv', header=FALSE)
colnames(x) <- c("source", "target", "value")
sankeyPlot <- rCharts$new()
sankeyPlot$set(
data = x,
nodeWidth = 15,
nodePadding = 10,
layout = 32,
width = 500,
height = 300,
units = "TWh",
title = "Sankey Diagram"
)
sankeyPlot$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey')
sankeyPlot$setTemplate(
afterScript = "
<script>
// to be specific in case you have more than one chart
d3.selectAll('#{{ chartId }} svg path.link')
.style('stroke', function(d){
//here we will use the source color
//if you want target then sub target for source
//or if you want something other than gray
//supply a constant
//or use a categorical scale or gradient
return d.source.color;
})
//note no changes were made to opacity
//to do uncomment below but will affect mouseover
//so will need to define mouseover and mouseout
//happy to show how to do this also
// .style('stroke-opacity', .7)
</script>
")
sankeyPlot
如果您想使用d3.scale.category??()
为了提供您的颜色,我假设您也希望对节点矩形进行类似的着色。以下是更改节点和链接颜色的一个示例。
sankeyPlot$setTemplate(
afterScript = "
<script>
var cscale = d3.scale.category20b();
// to be specific in case you have more than one chart
d3.selectAll('#{{ chartId }} svg path.link')
.style('stroke', function(d){
//here we will use the source color
//if you want target then sub target for source
//or if you want something other than gray
//supply a constant
//or use a categorical scale or gradient
//return d.source.color;
return cscale(d.source.name);
})
//note no changes were made to opacity
//to do uncomment below but will affect mouseover
//so will need to define mouseover and mouseout
//happy to show how to do this also
// .style('stroke-opacity', .7)
d3.selectAll('#{{ chartId }} svg .node rect')
.style('fill', function(d){
return cscale(d.name)
})
.style('stroke', 'none')
</script>
")
sankeyPlot
关于r - 向 rCharts 中的 Sankey 图添加颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25412223/
无论如何,我可以组合两个 rChart,例如 gvisMerge(obj1, obj2)。我意识到 rCharts 对象是函数。有没有办法结合R函数。我正在使用一个 Shiny 的应用程序,我想在其中
我正在尝试将 RChart 嵌入到 Shiny 的应用程序中。我专门使用 nPlot 函数来创建 type=scatterChart NVD3 样式图。在下面的 NVD3 网站示例中,我有兴趣在我的
这是我的数据: rawData <- structure(list(Date = c("4/30/2015", "5/1/2015", "5/2/2015", "5/3/2015", "5/4
我有以下问题;我在 NVD3 周围使用 rCharts 包装器来生成一个简单的折线图。我希望修改默认的提示信息行为。使用 NVD3 库,我已经能够使用以下代码做到这一点; .tooltipConten
我想强制所有刻度线和刻度标签沿 rCharts 中的轴出现nPlot 来自 nvd3图书馆。我尝试了几种方法都没有成功。 这是默认行为: df var chart = nv.mode
我使用以下代码生成 rCharts Sankey 图 ( https://github.com/timelyportfolio/rCharts_d3_sankey ): if(!require(rCh
我们在 rCharts 中使用 dplot(使用 dimple 库)尝试在 R Shiny 中创建气泡图。这一切都运行良好,但我们无法将特定颜色分配给特定气泡(或下面代码中的“ channel ”)。
我有一个 RCharts 问题(更普遍的是 Highcharts 需求)。我正在尝试构建一个包含 2 个类别和每个类别 2 个条形图的柱形图,这非常简单。 但是我无法显示我想要的颜色。默认情况下,每个
最近一直在试验slidify和 rCharts .使用 slidify 生成简单图表的教程是解释性的,但我找不到任何关于 rCharts 的此类教程。 例如,我知道下面会生成一个交互式绘图 data(
我正在使用 rCharts 创建一个散点图,显示我随时间计算的评分。我有每个单独的数据点(评级)的更多信息,并且希望图表上的每个数据点链接到一个唯一的页面,其中包含有关该特定数据点的更多信息。 例如:
如何通过运行多个带有 Shiny 和 rchart 的图表来覆盖输出显示选项,以便输出结果是 2x2 矩阵类型的网格布局。 require(rCharts) require(shiny) requir
rCharts 中的任何打包图表框架是否支持制作具有不同 y 轴的两个系列的时间序列图?在这种情况下,有人可以分享一个例子吗? 我查看了那里的文档以及图表框架网站上的文档,但没有找到任何内容。 最佳答
使用现有问题的答案作为可重现代码的基础 here 我收到以下错误,不确定为什么它不起作用...这似乎是渲染时的一个普遍问题 hPlot在 shiny 中键入图表,因为我不断收到相同的错误 Listen
这是我的代码: #Start up rickshaw charts library(rCharts) df.plot <- Rickshaw$new() #Set chart parameters d
我有一个如下所示的数据框: ## Data df % group_by(color) %>% # each serie is from one color do(data = list.par
我使用以下代码通过 rCharts 创建 Sankey 图。我希望增加桑基图上打印的文本的字体大小。我找不到指导我如何执行此操作的手册。想法? rm(list = ls()) require(resh
我想知道是否有办法将使用 rCharts 生成的图表保存到文件中(作为图像)。特别是,我想将使用“传单”生成的 map 保存到文件中。 例如,可以使用以下方法生成示例 map : require(rC
我使用以下代码通过 rCharts 创建 Sankey 图。我希望增加桑基图上打印的文本的字体大小。我找不到指导我如何执行此操作的手册。想法? rm(list = ls()) require(resh
我正在探索 rCharts。我在向 Y 轴和标题添加标签时陷入困境。我是 rCharts 新手。 这是我的示例代码 require(rCharts) n2 元素插入 rCharts分区这两个模板位于
我正在尝试重现页面上的代码:http://rcharts.io/parcoords/ cars /layouts/chart.html 我是不是做错了什么? 应该是这样的结果: 最佳答案 那个 re
我是一名优秀的程序员,十分优秀!