分组条形图显示组之间的交叉表 [英] Grouped bar chart displaying cross tab between groups

查看:137
本文介绍了分组条形图显示组之间的交叉表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个组条形图,该条形图给出两个组组合的频率.我参考此站点以获取汇总和嵌套功能参考: http://bl.ocks.org/phoebebright/raw/3176159/

I'm trying to make a group bar chart that gives the frequency of two group combos. I referred to this site for rollup and nest function reference: http://bl.ocks.org/phoebebright/raw/3176159/

我正在尝试使用自己的数据集来创建以下效果: https://bl.ocks.org/bricedev/0d95074b6d83a77dc3ad

I'm trying to use my own dataset to create the following effect: https://bl.ocks.org/bricedev/0d95074b6d83a77dc3ad

我当前使用我自己的数据drug1.csv进行的尝试: https://blockbuilder.org/lydiawawa/9efb5df76c08640316efbef702437db7

My current attempt with my own data, drug1.csv: https://blockbuilder.org/lydiawawa/9efb5df76c08640316efbef702437db7

在控制台中,分组计数似乎无法生成正确的分布.我的汇总和嵌套出现了问题

In the console, the grouped counts do not seem to generate the right distributions. Something is wrong with my rollup and nest

  const nestedData = d3.nest()
    .key(function(d){return d.s_category})
    .key(function(d){return d.drug_cat})
    .rollup(function(leaves) { return leaves.length; })
    .entries(data);

以下是s_category x drug_cat所需的交叉表分布计数:

Following is the desired cross tab distribution count of s_category x drug_cat :

      1   2   3   4   5   6
  2 367  35   8   1   1   1
  3 223  24   4   4   2   2
  4  29   5   9   1   2   3
  5  37   1   3   3   2  26

静态图表:

在我尝试创建的动画条形图中,交叉表计数应该是y轴,drug_c是x轴,而s_category确定条形图的组.谢谢您的帮助!

In the animated bar graph that I attempted to create, cross tab count should be the y-axis, drug_c is the x-axis and s_category determines the groups of the bar graph. Thank you for any help!

推荐答案

使用嵌套生成器后,就不再具有drug_catcount作为属性:您具有keyvalues(或value用于内部数组).

The moment you use the nest generator you don't have drug_cat and count as properties anymore: you have key and values (or value for the inner arrays).

这是您的块构建器,用于更改这些属性的名称: https://blockbuilder.org/GerardoFurtado/f4c825a558

Here is your block builder changing the names of those properties: https://blockbuilder.org/GerardoFurtado/f4c825a5f8c92e87cc5a81591ba1f7c9

这篇关于分组条形图显示组之间的交叉表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆