类似于在 ggplot 条形图和箱线图上放置星星 - 以指示显着性水平(p 值),我很感兴趣是否有一种方法可以在代表显着性比较的 vega 图上放置一些标记。
部分实现的示例规范:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A bar chart with significance indicators",
"data": {
"values": [
{"group": "DMSO", "value": 1.0},
{"group": "Compound 1", "value": 0.4},
{"group": "Compound 2", "value": 0.55}
]
},
"width": 300,
"height": 200,
"layer": [
{
"mark": "bar",
"encoding": {
"x": {"field": "group", "type": "nominal", "axis": {"labelAngle": 0}},
"y": {"field": "value", "type": "quantitative"},
"color": {"field": "group", "type": "nominal"}
}
},
{
"mark": {"type": "text", "fontSize": 14, "dy": -5},
"encoding": {
"x": {"field": "group", "type": "nominal"},
"y": {"field": "value", "type": "quantitative"},
"text": {"field": "value", "type": "quantitative", "format": ".2f"}
}
},
{
"data": {
"values": [
{"x": "DMSO", "x2": "Compound 1", "y": 1.3, "label": "**"},
{"x": "DMSO", "x2": "Compound 2", "y": 1.4, "label": "**"}
]
},
"mark": {"type": "rule"},
"encoding": {
"x": {"field": "x", "type": "nominal"},
"x2": {"field": "x2"},
"y": {"field": "y", "type": "quantitative"}
}
},
{
"data": {
"values": [
{"x": "Compound 1", "y": 1.32, "label": "**"},
{"x": "Compound 2", "y": 1.42, "label": "**"}
]
},
"mark": {"type": "text", "fontSize": 16, "fontWeight": "bold"},
"encoding": {
"x": {"field": "x", "type": "nominal"},
"y": {"field": "y", "type": "quantitative"},
"text": {"field": "label"}
}
}
]
}
您可以添加一些tick标记并将方向设置为垂直。
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A bar chart with significance indicators",
"data": {
"values": [
{"group": "DMSO", "value": 1},
{"group": "Compound 1", "value": 0.4},
{"group": "Compound 2", "value": 0.55}
]
},
"width": 300,
"height": 200,
"layer": [
{
"mark": "bar",
"encoding": {
"x": {"field": "group", "type": "nominal", "axis": {"labelAngle": 0}},
"y": {"field": "value", "type": "quantitative"},
"color": {"field": "group", "type": "nominal"}
}
},
{
"mark": {"type": "text", "fontSize": 13, "dy": -7},
"encoding": {
"x": {"field": "group", "type": "nominal"},
"y": {"field": "value", "type": "quantitative"},
"text": {"field": "value", "type": "quantitative", "format": ".2f"}
}
},
{
"data": {
"values": [
{"x": "DMSO", "y": 1.4},
{"x": "Compound 2", "y": 1.4},
{"x": "Compound 1", "y": 1.25},
{"x": "DMSO", "y": 1.25}
]
},
"mark": {
"type": "tick",
"orient": "vertical",
"color": "black",
"size": 7
},
"encoding": {
"x": {"field": "x", "type": "nominal"},
"y": {"field": "y", "type": "quantitative"},
"yOffset": {"value": 3}
}
},
{
"data": {
"values": [
{"x": "DMSO", "x2": "Compound 1", "y": 1.25, "label": "**"},
{"x": "DMSO", "x2": "Compound 2", "y": 1.4, "label": "**"}
]
},
"layer": [
{
"mark": {"type": "rule"},
"encoding": {
"x": {"field": "x", "type": "nominal"},
"x2": {"field": "x2"},
"y": {"field": "y", "type": "quantitative"}
}
},
{
"mark": {
"type": "text",
"fontSize": 16,
"fontWeight": "bold",
"xOffset": 10,
"yOffset": -3
},
"encoding": {
"x": {"field": "x2", "type": "nominal"},
"y": {"field": "y", "type": "quantitative"},
"text": {"field": "label"}
}
}
]
}
]
}