我正在学习d3.有一些方法可以在d3 js 中加载数据.但他们似乎都在制作HTTP GET.在我的场景中,我已经将json数据放在一个字符串中.如何使用此字符串而不是发出另一个http请求?我试图为此寻找文档,但没有找到.
这有效:
d3.json("/path/flare.json", function(json) {
//rendering logic here
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我有:
//assume this json comes from a server (on SAME DOMAIN)
var myjson = '{"name": "flare","children": [{"name": "analytics","children": [{"name": "cluster","children": [{"name": "MergeEdge", "size": 10 }]}]}]}';
Run Code Online (Sandbox Code Playgroud)
如何在d3中使用已计算的'myjson'并避免对服务器的异步调用?谢谢.
I'm using nvd3 and have a few charts where the legend is much to large. E.g. a scatter/bubble with 15 groups and the group names are long. The legend is so large that it leaves almost no room for the chart itself.
Is there a way to remove the legend or toggle the legend or limit the height/width it is taking up? Any example would be great.
Also, is there a way to have the bubble show a descriptive string? …
我看到了excel生成的情节,我想知道R是否也可以做到.
这张图片基本上是交叉表的可视化,比较了当天的天数与当天的首选膳食以及计算属于这些类别的人数.
我已经阅读了一些R气泡图,但我还没有看到这样的一个.有人能指出我的包裹或网站,解释我如何制作这样的情节?
我想在R中打印一个气泡图.我遇到的问题是,我的x和我的y轴都是离散的.从理论上讲,这意味着许多数据点(气泡)最终都在同一个坐标上.我宁愿将它们分散在数据点周围,但仍然在一个象限内,这使得气泡属于相应的x/y坐标.
我认为最好通过一个小例子来证明.以下代码应突出显示问题:
# Example
require(ggplot2)
zz <- textConnection("Row PowerSource ProductSegment Price Model ManufacturingLocation Quantity
1 High SegmentA Low ModA LocationA 5000
2 Low SegmentB Low ModB LocationB 25000
3 High SegmentC Low ModC LocationC 15000
4 Low SegmentD High ModD LocationD 30000
5 High SegmentE High ModE LocationA 2500
6 Low SegmentA Low ModF LocationB 110000
7 High SegmentB Low ModG LocationC 20000
8 Low SegmentC Low ModH LocationD 3500
9 High SegmentD Low ModI LocationA 65500
10 Low SegmentE …Run Code Online (Sandbox Code Playgroud) 使用Highcharts 3.0,可以创建类型为"bubble"的图表,而在3.0之前,必须使用"散点图"并修改标记大小以制作气泡图.旧方法的好处是你可以完全控制每个气泡的可见像素半径 - 新的气泡图自动调整气泡的大小,使它们相对于彼此的大小. 有没有办法关闭此行为或手动设置气泡半径?
前几天被问到这个问题,但没有人可以想象我的问题,所以我做了一个例子.
A <- c('a','b', 'c','d','e')
types <- factor(A)
B <- c(1,2,3,4,5)
C <- c(6,7,8,9,10)
D <- c(1,2,1,2,3)
ABC <- data.frame(B,C,D,types)
library(ggplot2)
ggplot(ABC, aes(x=B ,y=C ,size=D, colour=as.factor(types),label=types, shape=as.factor(types))) +
geom_point()+geom_text(size=2, hjust=0,colour="black", vjust=0) +
scale_size_area(max_size=20, "D", breaks=c(100,500,1000,3000,5000)) +
scale_x_log10(lim=c(0.05,10),breaks=c(0.1,1,10))+ scale_y_continuous(lim=c(0,30000000)) +
scale_shape_manual(values=c(15,18,16,17,19))`
Run Code Online (Sandbox Code Playgroud)
绘制这个图表,你会有因素有颜色和形状归因于它们.
在我的代码中,我使用scale_shape_manual来设置形状,它们按顺序定义,即因子的顺序是a,b,c,d,e,我的值是15,18,16,17,19,所以a = 15(a方形),b = 18等
我想按因子设置这些形状.我的数据每天都在变化,因素将以不同的顺序排列,但我总是希望相同的因素具有相同的形状.
显然这段代码不起作用,但是类似于:
scale_shape_manual(values=('a'=15, 'b'=18, 'c'=16, 'd'=17, 'e'=19))
如果我也可以做同样的颜色会有所帮助.
谢谢
我正在尝试修改此代码bl.ocks.org/mbostock/7881887,以便我可以使用该技术来显示一个词云,其中圆圈大小相对于文件中的单词的数量,但我的主要问题是一刻找出如何在圆圈中添加文字.很诱人地,我可以看到在代码中看起来像函数的函数... node.append("text")?所以我假设我能够在节点函数中向"d"添加"name"值,然后我们就去了.如你所见,我刚刚添加了名称:text其中text ="Test"为d.任何帮助让任何文字出现在这些圈子内或附近的任何帮助都将非常感激!我是新的D3,你可能会说,并且已经花了很多个晚上用谷歌搜索这个什么都没找到.我可以看到一个不同类型的图表上的例子......力量布局,例如http://bl.ocks.org/mbostock/1093130但它们看起来如此不同我不能将一个应用于另一个:-(
这是我的jsfiddle https://jsfiddle.net/TimBrighton/vn7reroe/1/
var width = 960,
height = 500,
padding = 1.5, // separation between same-color nodes
clusterPadding = 6, // separation between different-color nodes
maxRadius = 12;
var n = 100, // total number of nodes
m = 5; // number of distinct clusters
var color = d3.scale.category10()
.domain(d3.range(m));
// The largest node for each cluster.
var clusters = new Array(m);
var nodes = d3.range(n).map(function() {
test="Test";
var i = Math.floor(Math.random() * m),
r …Run Code Online (Sandbox Code Playgroud) 我想使用这个(http://vallandingham.me/vis/gates/)气泡图(在D3中制作):

...演练一些不同的场景。简而言之,我想可视化选举数据。政党获得了多少票,在什么情况下可能组建政府?
在数据层面,非常明显:名称、议会席位数、state1、state2、state3等。State1是1或2。1是政府中的一个地方,2是反对派。非常简单。
但该示例仅显示两种状态:“所有补助金”和“按年份补助金”。我想要的是更多像按年拨款这样的州。但我不是一个很好的程序员,无法弄清楚如何使这项工作有效。当我添加新状态时,可视化不起作用。
这是控制状态的代码(Coffee)。
class BubbleChart
constructor: (data) ->
@data = data
@width = 940
@height = 600
@tooltip = CustomTooltip("gates_tooltip", 240)
# locations the nodes will move towards
# depending on which view is currently being
# used
@center = {x: @width / 2, y: @height / 2}
@year_centers = {
"2008": {x: @width / 3, y: @height / 2},
"2009": {x: @width / 2, y: @height / 2},
"2010": {x: 2 * @width / 3, …Run Code Online (Sandbox Code Playgroud) 我想在 R 中重现以下情节:
我现在使用packcircles包,并且能够创建图中的绘图:
使用以下代码:
require(packcircles)
res <- circleLayout(xyr, limits, limits, maxiter = 1000)
dat <- circlePlotData(res$layout)
doPlot <- function(dat, title)
ggplot(dat) +
geom_polygon(aes(x, y, group=id), colour="tomato", fill="tomato", alpha=0.3) +
coord_equal(xlim=limits, ylim=limits) +
theme_bw() +
theme(axis.text=element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank()) +
labs(title=title)
doPlot(dat, "")
Run Code Online (Sandbox Code Playgroud)
其中xyr是以下形式的数据框:
x y r
1 2.897344 -10.4161236 0.57
2 1.932411 13.0631120 0.52
3 6.839500 -11.0507209 0.52
4 11.117047 -17.6440597 0.77
5 22.395529 -0.6191146 0.45
6 20.313309 -13.3292887 0.69
Run Code Online (Sandbox Code Playgroud)
以及表单的输出数据:
x y id
1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用seaborn创建3D点(x,y,z)的彩色气泡图,每个坐标都是[0,255]范围内的整数。我希望轴代表 x 和 y,散点气泡的色调和大小代表 z 坐标。
代码:
import seaborn
seaborn.set()
import pandas
import matplotlib.pyplot
x = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200]
y = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200]
z = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200]
df = pandas.DataFrame(list(zip(x, y, z)), columns =['x', 'y', 'z'])
ax = seaborn.scatterplot(x="x", y="y",
hue="z",
data=df)
matplotlib.pyplot.xlim(0,255)
matplotlib.pyplot.ylim(0,255)
matplotlib.pyplot.show()
Run Code Online (Sandbox Code Playgroud)
几乎让我得到了我想要的:
然而,这使得色调范围基于 z 中的数据。相反,我想根据最小和最大 z 值的范围(如 …
bubble-chart ×10
d3.js ×4
r ×4
force-layout ×2
ggplot2 ×2
coffeescript ×1
crosstab ×1
drawing ×1
geometry ×1
highcharts ×1
javascript ×1
json ×1
legend ×1
nvd3.js ×1
plot ×1
python ×1
scatter-plot ×1
seaborn ×1
shape ×1
word-cloud ×1