英文:
Point chart - two (or more) data rows
问题
我想要在点图上为每个X轴值添加平均的Y轴值。有办法可以做到这点吗?我希望实现类似第二张图片的结果。
数据示例
id | datum | year | month | day | weekday | hour | hourly_steps | cumulative_daily_steps | daily_steps |
---|---|---|---|---|---|---|---|---|---|
1 | 2021-01-01 | 2021 | 1 | 1 | 5 | 17 | 49 | 49 | 5837 |
2 | 2021-01-01 | 2021 | 1 | 1 | 5 | 18 | 4977 | 5026 | 5837 |
3 | 2021-01-01 | 2021 | 1 | 1 | 5 | 19 | 692 | 5718 | 5837 |
4 | 2021-01-01 | 2021 | 1 | 1 | 5 | 20 | 13 | 5731 | 5837 |
5 | 2021-01-01 | 2021 | 1 | 1 | 5 | 22 | 106 | 5837 | 5837 |
6 | 2021-01-02 | 2021 | 1 | 2 | 6 | 6 | 48 | 48 | 7965 |
7 | 2021-01-02 | 2021 | 1 | 2 | 6 | 9 | 97 | 145 | 7965 |
8 | 2021-01-02 | 2021 | 1 | 2 | 6 | 10 | 1109 | 1254 | 7965 |
9 | 2021-01-02 | 2021 | 1 | 2 | 6 | 11 | 253 | 1507 | 7965 |
10 | 2021-01-02 | 2021 | 1 | 2 | 6 | 12 | 126 | 1633 | 7965 |
11 | 2021-01-02 | 2021 | 1 | 2 | 6 | 13 | 51 | 1684 | 7965 |
12 | 2021-01-02 | 2021 | 1 | 2 | 6 | 14 | 690 | 2374 | 7965 |
13 | 2021-01-02 | 2021 | 1 | 2 | 6 | 15 | 3690 | 6064 | 7965 |
14 | 2021-01-02 | 2021 | 1 | 2 | 6 | 16 | 956 | 7020 | 7965 |
15 | 2021-01-02 | 2021 | 1 | 2 | 6 | 17 | 667 | 7687 | 7965 |
16 | 2021-01-02 | 2021 | 1 | 2 | 6 | 18 | 36 | 7723 | 7965 |
17 | 2021-01-02 | 2021 | 1 | 2 | 6 | 19 | 45 | 7768 | 7965 |
18 | 2021-01-02 | 2021 | 1 | 2 | 6 | 20 | 38 | 7806 | 7965 |
19 | 2021-01-02 | 2021 | 1 | 2 | 6 | 21 | 47 | 7853 | 7965 |
20 | 2021-01-02 | 2021 | 1 | 2 | 6 | 22 | 15 | 7868 | 7965 |
21 | 2021-01-02 | 2021 | 1 | 2 | 6 | 23 | 97 | 7965 | 7965 |
22 | 2021-01-03 | 2021 | 1 | 3 | 7 | 0 | 147 | 147 | 8007 |
23 | 2021-01-03 | 2021 | 1 | 3 | 7 | 7 | 15 | 162 | 8007 |
24 | 2021-01-03 | 2021 | 1 | 3 | 7 | 8 | 54 | 216 | 8007 |
25 | 2021-01-03 | 2021 | 1 | 3 | 7 | 9 | 47 | 263 | 8007 |
26 | 2021-01-03 | 2021 | 1 | 3 | 7 | 10 | 16 | 279 | 8007 |
27 | 2021-01-03 | 2021 | 1 | 3 | 7 | 11 | 16 | 295 | 8007 |
28 | 2021-01-03 | 2021 | 1 | 3 | 7 | 12 | 61 | 356 | 8007 |
29 | 2021-01-03 | 2021 | 1 | 3 | 7 | 13 | 1459 | 1815 | 8007 |
30 | 2021-01-03 | 2021 | 1 | 3 | 7 | 14 | 2869 | 4684 | 8007 |
31 | 2021-01-03 | 2021 | 1 | 3 | 7 | 15 | 2670 | 7354 | 8007 |
32 | 2021-01-03 | 2021 | 1 | 3 | 7 | 16 | 131 | 7485 | 8007 |
33 | 2021-01-03 | 2021 | 1 | 3 | 7 | 17 | 67 | 7552 | 8007 |
34 | 2021-01-03 | 2021 | 1 | 3 | 7 | 18 | 27 | 7579 | 8007 |
35 | 2021-01-03 | 2021 | 1 | 3 | 7 | 19 | 50 | 7629 | 8007 |
36 | 2021-01-03 | 2021 | 1 | 3 | 7 | 20 |
英文:
I would like to add the average Y-axis values for each X-axis value to a point chart. Is there any way to do this please? I would like to achieve a similar result to the second picture.
Data example
id | datum | year | month | day | weekday | hour | hourly_steps | cumulative_daily_steps | daily_steps |
---|---|---|---|---|---|---|---|---|---|
1 | 2021-01-01 | 2021 | 1 | 1 | 5 | 17 | 49 | 49 | 5837 |
2 | 2021-01-01 | 2021 | 1 | 1 | 5 | 18 | 4977 | 5026 | 5837 |
3 | 2021-01-01 | 2021 | 1 | 1 | 5 | 19 | 692 | 5718 | 5837 |
4 | 2021-01-01 | 2021 | 1 | 1 | 5 | 20 | 13 | 5731 | 5837 |
5 | 2021-01-01 | 2021 | 1 | 1 | 5 | 22 | 106 | 5837 | 5837 |
6 | 2021-01-02 | 2021 | 1 | 2 | 6 | 6 | 48 | 48 | 7965 |
7 | 2021-01-02 | 2021 | 1 | 2 | 6 | 9 | 97 | 145 | 7965 |
8 | 2021-01-02 | 2021 | 1 | 2 | 6 | 10 | 1109 | 1254 | 7965 |
9 | 2021-01-02 | 2021 | 1 | 2 | 6 | 11 | 253 | 1507 | 7965 |
10 | 2021-01-02 | 2021 | 1 | 2 | 6 | 12 | 126 | 1633 | 7965 |
11 | 2021-01-02 | 2021 | 1 | 2 | 6 | 13 | 51 | 1684 | 7965 |
12 | 2021-01-02 | 2021 | 1 | 2 | 6 | 14 | 690 | 2374 | 7965 |
13 | 2021-01-02 | 2021 | 1 | 2 | 6 | 15 | 3690 | 6064 | 7965 |
14 | 2021-01-02 | 2021 | 1 | 2 | 6 | 16 | 956 | 7020 | 7965 |
15 | 2021-01-02 | 2021 | 1 | 2 | 6 | 17 | 667 | 7687 | 7965 |
16 | 2021-01-02 | 2021 | 1 | 2 | 6 | 18 | 36 | 7723 | 7965 |
17 | 2021-01-02 | 2021 | 1 | 2 | 6 | 19 | 45 | 7768 | 7965 |
18 | 2021-01-02 | 2021 | 1 | 2 | 6 | 20 | 38 | 7806 | 7965 |
19 | 2021-01-02 | 2021 | 1 | 2 | 6 | 21 | 47 | 7853 | 7965 |
20 | 2021-01-02 | 2021 | 1 | 2 | 6 | 22 | 15 | 7868 | 7965 |
21 | 2021-01-02 | 2021 | 1 | 2 | 6 | 23 | 97 | 7965 | 7965 |
22 | 2021-01-03 | 2021 | 1 | 3 | 7 | 0 | 147 | 147 | 8007 |
23 | 2021-01-03 | 2021 | 1 | 3 | 7 | 7 | 15 | 162 | 8007 |
24 | 2021-01-03 | 2021 | 1 | 3 | 7 | 8 | 54 | 216 | 8007 |
25 | 2021-01-03 | 2021 | 1 | 3 | 7 | 9 | 47 | 263 | 8007 |
26 | 2021-01-03 | 2021 | 1 | 3 | 7 | 10 | 16 | 279 | 8007 |
27 | 2021-01-03 | 2021 | 1 | 3 | 7 | 11 | 16 | 295 | 8007 |
28 | 2021-01-03 | 2021 | 1 | 3 | 7 | 12 | 61 | 356 | 8007 |
29 | 2021-01-03 | 2021 | 1 | 3 | 7 | 13 | 1459 | 1815 | 8007 |
30 | 2021-01-03 | 2021 | 1 | 3 | 7 | 14 | 2869 | 4684 | 8007 |
31 | 2021-01-03 | 2021 | 1 | 3 | 7 | 15 | 2670 | 7354 | 8007 |
32 | 2021-01-03 | 2021 | 1 | 3 | 7 | 16 | 131 | 7485 | 8007 |
33 | 2021-01-03 | 2021 | 1 | 3 | 7 | 17 | 67 | 7552 | 8007 |
34 | 2021-01-03 | 2021 | 1 | 3 | 7 | 18 | 27 | 7579 | 8007 |
35 | 2021-01-03 | 2021 | 1 | 3 | 7 | 19 | 50 | 7629 | 8007 |
36 | 2021-01-03 | 2021 | 1 | 3 | 7 | 20 | 48 | 7677 | 8007 |
37 | 2021-01-03 | 2021 | 1 | 3 | 7 | 22 | 119 | 7796 | 8007 |
38 | 2021-01-03 | 2021 | 1 | 3 | 7 | 23 | 211 | 8007 | 8007 |
39 | 2021-01-04 | 2021 | 1 | 4 | 1 | 4 | 19 | 19 | 6022 |
40 | 2021-01-04 | 2021 | 1 | 4 | 1 | 6 | 94 | 113 | 6022 |
41 | 2021-01-04 | 2021 | 1 | 4 | 1 | 10 | 48 | 161 | 6022 |
42 | 2021-01-04 | 2021 | 1 | 4 | 1 | 11 | 97 | 258 | 6022 |
43 | 2021-01-04 | 2021 | 1 | 4 | 1 | 12 | 48 | 306 | 6022 |
44 | 2021-01-04 | 2021 | 1 | 4 | 1 | 13 | 39 | 345 | 6022 |
45 | 2021-01-04 | 2021 | 1 | 4 | 1 | 14 | 499 | 844 | 6022 |
46 | 2021-01-04 | 2021 | 1 | 4 | 1 | 15 | 799 | 1643 | 6022 |
47 | 2021-01-04 | 2021 | 1 | 4 | 1 | 16 | 180 | 1823 | 6022 |
48 | 2021-01-04 | 2021 | 1 | 4 | 1 | 17 | 55 | 1878 | 6022 |
49 | 2021-01-04 | 2021 | 1 | 4 | 1 | 18 | 27 | 1905 | 6022 |
50 | 2021-01-04 | 2021 | 1 | 4 | 1 | 19 | 2246 | 4151 | 6022 |
51 | 2021-01-04 | 2021 | 1 | 4 | 1 | 20 | 1518 | 5669 | 6022 |
52 | 2021-01-04 | 2021 | 1 | 4 | 1 | 21 | 247 | 5916 | 6022 |
53 | 2021-01-04 | 2021 | 1 | 4 | 1 | 22 | 106 | 6022 | 6022 |
54 | 2021-01-05 | 2021 | 1 | 5 | 2 | 4 | 18 | 18 | 7623 |
55 | 2021-01-05 | 2021 | 1 | 5 | 2 | 6 | 44 | 62 | 7623 |
56 | 2021-01-05 | 2021 | 1 | 5 | 2 | 7 | 51 | 113 | 7623 |
57 | 2021-01-05 | 2021 | 1 | 5 | 2 | 8 | 450 | 563 | 7623 |
58 | 2021-01-05 | 2021 | 1 | 5 | 2 | 9 | 385 | 948 | 7623 |
59 | 2021-01-05 | 2021 | 1 | 5 | 2 | 10 | 469 | 1417 | 7623 |
60 | 2021-01-05 | 2021 | 1 | 5 | 2 | 11 | 254 | 1671 | 7623 |
61 | 2021-01-05 | 2021 | 1 | 5 | 2 | 12 | 1014 | 2685 | 7623 |
62 | 2021-01-05 | 2021 | 1 | 5 | 2 | 13 | 415 | 3100 | 7623 |
63 | 2021-01-05 | 2021 | 1 | 5 | 2 | 14 | 297 | 3397 | 7623 |
64 | 2021-01-05 | 2021 | 1 | 5 | 2 | 15 | 31 | 3428 | 7623 |
65 | 2021-01-05 | 2021 | 1 | 5 | 2 | 17 | 50 | 3478 | 7623 |
66 | 2021-01-05 | 2021 | 1 | 5 | 2 | 18 | 3771 | 7249 | 7623 |
67 | 2021-01-05 | 2021 | 1 | 5 | 2 | 19 | 52 | 7301 | 7623 |
68 | 2021-01-05 | 2021 | 1 | 5 | 2 | 20 | 96 | 7397 | 7623 |
69 | 2021-01-05 | 2021 | 1 | 5 | 2 | 21 | 59 | 7456 | 7623 |
70 | 2021-01-05 | 2021 | 1 | 5 | 2 | 22 | 167 | 7623 | 7623 |
71 | 2021-01-06 | 2021 | 1 | 6 | 3 | 6 | 54 | 54 | 7916 |
72 | 2021-01-06 | 2021 | 1 | 6 | 3 | 7 | 1223 | 1277 | 7916 |
73 | 2021-01-06 | 2021 | 1 | 6 | 3 | 8 | 118 | 1395 | 7916 |
74 | 2021-01-06 | 2021 | 1 | 6 | 3 | 10 | 77 | 1472 | 7916 |
75 | 2021-01-06 | 2021 | 1 | 6 | 3 | 11 | 709 | 2181 | 7916 |
76 | 2021-01-06 | 2021 | 1 | 6 | 3 | 12 | 123 | 2304 | 7916 |
77 | 2021-01-06 | 2021 | 1 | 6 | 3 | 13 | 36 | 2340 | 7916 |
78 | 2021-01-06 | 2021 | 1 | 6 | 3 | 14 | 14 | 2354 | 7916 |
79 | 2021-01-06 | 2021 | 1 | 6 | 3 | 15 | 156 | 2510 | 7916 |
80 | 2021-01-06 | 2021 | 1 | 6 | 3 | 16 | 149 | 2659 | 7916 |
81 | 2021-01-06 | 2021 | 1 | 6 | 3 | 17 | 995 | 3654 | 7916 |
82 | 2021-01-06 | 2021 | 1 | 6 | 3 | 18 | 2022 | 5676 | 7916 |
83 | 2021-01-06 | 2021 | 1 | 6 | 3 | 19 | 34 | 5710 | 7916 |
84 | 2021-01-06 | 2021 | 1 | 6 | 3 | 21 | 937 | 6647 | 7916 |
85 | 2021-01-06 | 2021 | 1 | 6 | 3 | 22 | 1208 | 7855 | 7916 |
86 | 2021-01-06 | 2021 | 1 | 6 | 3 | 23 | 61 | 7916 | 7916 |
答案1
得分: 1
以下是翻译好的部分:
数据:
在Deneb内,粘贴以下规范。
{
"data": {"name": "dataset"},
"transform": [
{
"calculate": "datum['weekday ']<= 5?'weekday':'weekend'",
"as": "type"
}
],
"layer": [
{"mark": {"type": "point"}},
{
"mark": {"type": "line", "interpolate":"basis"},
"encoding": {
"x": {
"field": "hour"
},
"y": {
"aggregate": "mean",
"field": "cumulative_daily_steps"
}
}
}
],
"encoding": {
"x": {
"field": "hour",
"type": "quantitative",
"axis": {"title": "Hour of Day"}
},
"y": {
"field": "cumulative_daily_steps",
"type": "quantitative",
"axis": {
"title": "Cumulative Step Count"
}
},
"color": {
"field": "type",
"type": "nominal",
"scale": {
"range": ["red", "green"]
},
"legend": {"title": ""}
}
}
}
英文:
Here you go.
Data:
Add Deneb visual and then add the following fields ensuring that don't summarise is selected for each column.
Inside Deneb, paste the following spec.
{
"data": {"name": "dataset"},
"transform": [
{
"calculate": "datum['weekday ']<= 5?'weekday':'weekend'",
"as": "type"
}
],
"layer": [
{"mark": {"type": "point"}},
{
"mark": {"type": "line", "interpolate":"basis"},
"encoding": {
"x": {
"field": "hour"
},
"y": {
"aggregate": "mean",
"field": "cumulative_daily_steps"
}
}
}
],
"encoding": {
"x": {
"field": "hour",
"type": "quantitative",
"axis": {"title": "Hour of Day"}
},
"y": {
"field": "cumulative_daily_steps",
"type": "quantitative",
"axis": {
"title": "Cumulative Step Count"
}
},
"color": {
"field": "type",
"type": "nominal",
"scale": {
"range": ["red", "green"]
},
"legend": {"title": ""}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论