首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在vega-lite中排序标称轴值

在vega-lite中排序标称轴值
EN

Stack Overflow用户
提问于 2017-06-08 20:41:36
回答 0查看 600关注 0票数 1

我有一个vega-lite分层条形图来比较likert scale前后的调查结果。X轴具有likert选项,但这些选项是按字母顺序排序的。X轴值的顺序可以排序吗?例如“强烈不同意,不同意,神经质,同意,强烈同意”?

vega-lite示例代码:

代码语言:javascript
复制
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"description": "A bar chart showing the US population distribution of     age groups and gender in 2000.",
"data": { 
  "values": [
    {"type":"pre", "answer":"Strongly Disagree", "total":15},
    {"type":"post", "answer":"Strongly Disagree", "total":30},
    {"type":"pre", "answer":"Disagree", "total":15},
    {"type":"post", "answer":"Disagree", "total":30},
    {"type":"pre", "answer":"Neutral", "total":15},
    {"type":"post", "answer":"Neutral", "total":30},
    {"type":"pre", "answer":"Neutral", "total":15},
    {"type":"post", "answer":"Neutral", "total":30},
    {"type":"pre", "answer":"Agree", "total":15},
    {"type":"post", "answer":"Agree", "total":30},
    {"type":"pre", "answer":"Strongly Agree", "total":20},
    {"type":"post", "answer":"Strongly Agree", "total":40}
  ]
},
"mark": "bar",
"encoding": {
    "x": {
      "field": "answer", "type": "nominal"
    },
    "y": {
      "field": "total", "type": "quantitative",
      "axis": {"title": "% Counts"},
      "stack": "none"
    },
    "color": {
      "field": "type", "type": "nominal",
      "axis": {"title": "Answer"},
      "scale": {"range": ["#e377c2","#1f77b4"]}
    },
    "opacity": {"value": 0.7}
}
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44436110

复制
相关文章

相似问题

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