d3 制作条形图_停止制作常见的坏条形图的5个简单技巧
d3 制作條形圖
Bar charts were probably the first type of chart you were ever introduced to in first grade. Their simplicity makes them a standard in visualizing data, but it is its accessibility that leads visualizers to often be careless with bar charts.
乙 AR圖表很可能是第一種類型,你在第一級(jí)是有史以來推出的圖表。 它們的簡(jiǎn)單性使其成為可視化數(shù)據(jù)的標(biāo)準(zhǔn),但是正是它的可訪問性導(dǎo)致可視化工具經(jīng)常對(duì)條形圖不小心。
Bar charts are one of the most basic forms of data representation — a continuous variable against a discrete variable — but they are so often presented in ways that could be significantly improved.
條形圖是數(shù)據(jù)表示的最基本形式之一-連續(xù)變量相對(duì)于離散變量-但經(jīng)常以可以顯著改進(jìn)的方式呈現(xiàn)。
In this article, I’ll present five tips you can use to make your bar plot deliver the message it intends to more effectively.
在本文中,我將介紹五個(gè)技巧,您可以使用它們使條形圖更有效地傳達(dá)其意圖。
1 | 請(qǐng)注意您如何為圖表著色。 (1 | Be careful how you color your charts.)
Colors are essential in any chart. They can convey meaning and draw attention to certain parts of the data.
在任何圖表中顏色都是必不可少的。 它們可以傳達(dá)含義并引起對(duì)數(shù)據(jù)某些部分的注意。
Don’t use vibrant colors for data that conveys the same meaning. Instead, the bars should be similar shades of a color, for example, in the chart below, and can convey a meaning.
不要將鮮艷的色彩用于傳達(dá)相同含義的數(shù)據(jù)。 相反,例如,在下面的圖表中,條形圖應(yīng)為相似的顏色陰影,并且可以傳達(dá)含義。
Because, in this case, the x-axis should not be moved around to sort the bars by greatest-to-smallest or smallest-to-greatest (the optimal presentation), colors can be used to put more emphasis on how bars perform relative to other bars, even when they are not in lateral comparison to each other.
因?yàn)樵谶@種情況下,不應(yīng)移動(dòng)x軸按最大到最小或最小到最大(最佳表示)對(duì)條形進(jìn)行排序,因此可以使用顏色來強(qiáng)調(diào)條形相對(duì)即使它們不在橫向上相互比較
Don’t use a color palette that has the same color but too drastic a change in shade. The below plot’s dark color for E makes comparison with A difficult.
不要使用顏色相同但色調(diào)變化過大的調(diào)色板。 下圖的E暗色使得難以與A進(jìn)行比較。
Don’t use colors for thematic representation, like red and green to show Christmas sales:
請(qǐng)勿將顏色用于主題表示,例如紅色和綠色代表圣誕節(jié)銷售:
This can be corny and confusing in the cases where the color pattern interferes with traditional color understandings, such as in column E, when the red sub-bar is higher than the green one.
在紅色子欄高于綠色子欄的情況下,如果顏色模式干擾傳統(tǒng)的顏色理解(例如在E列中),這可能會(huì)很老套和令人困惑。
Colors can also be used to put emphasis on certain bars, such as the highest and lowest values.
顏色也可以用來強(qiáng)調(diào)某些條形,例如最高和最低值。
In this case, by using a dimmed, grey value for the values in-between, the audience is much more drawn to columns A and E. The red color for A and the green color for E make it clear which one performs better (in scenarios where lower is better, A and E should have switched colors).
在這種情況下,通過為中間的值使用灰暗的灰色值,觀眾將更多地吸引到A和E列。A的紅色和E的綠色可以清楚地看出哪個(gè)效果更好(在越低越好的情況,A和E應(yīng)該切換顏色)。
When choosing colors, many of the ready-to-use palettes in plotting libraries like seaborn will suffice, but if you want to do things like choosing the exact color of particular bars, you will need to give the plotting library the hex code for that color. A particularly helpful resource for choosing them is w3school’s HTML color picker.
選擇顏色時(shí),諸如seaborn的繪圖庫(kù)中的許多現(xiàn)成的調(diào)色板就足夠了,但是如果要進(jìn)行諸如選擇特定條形的確切顏色之類的操作,則需要為繪圖庫(kù)提供相應(yīng)的十六進(jìn)制代碼顏色。 選擇它們的一個(gè)特別有用的資源是w3school的HTML顏色選擇器 。
Usually, the boxed region is a good place to choose your colors — anything lower or higher is usually either too light, too saturated, or too dark. Only use one main color (wherever you choose your color in the hexagon to the left), and choose various percentages of that color — it will make your plot look a lot smoother and cleaner.
通常,盒裝區(qū)域是選擇顏色的好地方-較低或較高的顏色通常太亮,太飽和或太暗。 僅使用一種主要顏色(無論您在左側(cè)的六邊形中選擇什么顏色),然后選擇該顏色的不同百分比-這將使您的繪圖看起來更加平滑和整潔。
However, be careful what colors you choose. For example, this color is neon-green and much too bright.
但是,請(qǐng)注意選擇哪種顏色。 例如,此顏色是霓虹綠且太亮。
A bright bar is difficult for the audience to look at — your colors should always be muted, conservative, and easygoing on the eyes. Usually, picking colors on the rims of the hexagon and choosing lighter percentages will yield favorable colors.
觀眾很難看清楚明亮的條形-您的顏色應(yīng)始終保持柔和,保守和隨和的色彩。 通常,在六邊形的邊緣上拾取顏色并選擇較淺的百分比將產(chǎn)生有利的顏色。
2 | 停止旋轉(zhuǎn)軸標(biāo)簽。 (2 | Stop rotating your axis labels.)
Your job as a data visualizer is to make the main idea or insight clear to the audience — it’s not their job to understand your visualization.
作為數(shù)據(jù)可視化工具,您的工作是使主要想法或見解對(duì)聽眾清晰可見-了解可視化不是他們的工作。
The reasoning behind rotating the axis labels is that when they are too long, they begin to overlap:
旋轉(zhuǎn)軸標(biāo)簽的原因是,當(dāng)它們過長(zhǎng)時(shí),它們開始重疊:
So they’re usually rotated 90 degrees.
因此它們通常旋轉(zhuǎn)90度。
Reading the labels requires either turning your head 90 degrees or thinking in a tilted dimension, then reverting back to a horizontal tilt to evaluate the position of the bars.
閱讀標(biāo)簽需要將您的頭旋轉(zhuǎn)90度或以傾斜的角度思考,然后返回到水平傾斜以評(píng)估條形的位置。
Turning the labels 45 degrees is no better. Because almost all plotting libraries rotate labels at their center, it’s difficult to point out which label correlates with which bar when AAA…’s label is pointing to BBB’s bar.
將標(biāo)簽旋轉(zhuǎn)45度也不是更好。 因?yàn)閹缀跛械睦L圖庫(kù)都在其中心旋轉(zhuǎn)標(biāo)簽,所以當(dāng)AAA…的標(biāo)簽指向BBB的標(biāo)簽時(shí),很難指出哪個(gè)標(biāo)簽與哪個(gè)標(biāo)簽相關(guān)。
All of these problems can simply be avoided with a horizontal bar chart with a background grid to further assist in easy comparison.
使用帶有背景網(wǎng)格的水平條形圖可以輕松避免所有這些問題,以進(jìn)一步幫助輕松進(jìn)行比較。
Much better! The labels are clear and comparison is as easy as a vertical bar plot.
好多了! 標(biāo)簽清晰明了,比較就像垂直條形圖一樣容易。
3 | 不要在水平條形圖上使用負(fù)值。 (3 | Don’t use negative values on a horizontal bar chart.)
Negative values on a horizontal bar chart are never as effective as negative values on a vertical bar chart.
水平條形圖上的負(fù)值永遠(yuǎn)不會(huì)像垂直條形圖上的負(fù)值一樣有效。
Left and right are never correlated with negative and positive (respectively), but up and down are.
左和右從不分別與負(fù)和正相關(guān),而向上和向下則不相關(guān)。
An up-down model accented by deeper shades for greater absolute values are much for effective and powerful.
以更深的陰影強(qiáng)調(diào)更大的絕對(duì)值的重載模型對(duì)于有效和強(qiáng)??大是非常重要的。
4 | 永遠(yuǎn)不會(huì)有雙向水平條形圖。 (4 | Never, ever have two-way horizontal bar charts.)
Demographic charts often like to plot two-way horizontal bar charts. This is a very, very bad idea — humans simply cannot compare bar lengths that are opposite each other. In addition, humans have biases to certain directions: if a bar length is too close to call, usually humans will instinctively think the right one is longer.
人口統(tǒng)計(jì)圖通常喜歡繪制雙向水平條形圖。 這是一個(gè)非常非常糟糕的主意-人類根本無法比較彼此相對(duì)的鋼筋長(zhǎng)度。 另外,人類在某些方向上有偏見:如果一根柱線的長(zhǎng)度太近而無法調(diào)用,通常人們會(huì)本能地認(rèn)為正確的柱線更長(zhǎng)。
In category B, one of the bars is 5% longer than the other. Can you spot which?
在類別B中,一根鋼筋比另一根鋼筋長(zhǎng)5%。 你能發(fā)現(xiàn)哪個(gè)?
Instead, to compare, a vertical and lateral comparison will serve the purpose much better.
相反,要進(jìn)行比較,縱向和橫向比較會(huì)更好地達(dá)到目的。
It is more obvious now that the Male sub bar is longer than the Female sub bar. Plotting these out vertically makes comparison much easier.
現(xiàn)在,很明顯,“男性”子欄比“女性”子欄更長(zhǎng)。 垂直繪制這些圖可以使比較容易得多。
5 | 截?cái)嗍鞘д妗?(5 | Truncation is distortion.)
Sometimes, visualizers will truncate, or cut off part of the bottom, of a chart, in the case that the difference between bars is trivial.
有時(shí),在條形圖之間的差異很小的情況下,可視化工具會(huì)截?cái)嗷蚯袛鄨D表底部的一部分。
This is a distortion of the actual data. Even with the y labels, humans instinctively set the bottom as the baseline, and hence, make assumptions about the relative size of the bars based on the zero baseline. D is 3 to four times smaller than C, and C about 1.3 times B, the average person’s mind would instinctively assert, even with the y-axis labels.
這是實(shí)際數(shù)據(jù)的失真。 即使使用y標(biāo)簽,人類也可以本能地將底部設(shè)置為基線,因此,可以基于零基線對(duì)條形的相對(duì)大小進(jìn)行假設(shè)。 D是C的3到4倍,C是B的1.3倍,即使使用y軸標(biāo)簽,普通人的大腦也會(huì)本能地?cái)嘌浴?
Numbers are never as powerful as shapes; this is the fundamental premise of visualization.
數(shù)字從來沒有像形狀那么強(qiáng)大。 這是可視化的基本前提。
The complete, untruncated data tells an entirely different story.
完整,完整的數(shù)據(jù)講述了一個(gè)完全不同的故事。
If you are concerned about the difference between bars not being expressed clearly enough, the figure can be stretched out vertically:
如果您擔(dān)心條形圖之間的差異不夠清楚,可以將圖形垂直拉伸:
This amplifies differences onto a larger scale without taking away from the full picture — always start at the 0 baseline.
這會(huì)將差異放大到更大的范圍,而又不會(huì)影響整體效果-始終從0基線開始。
Better visualizations equate to better understanding of the data — and when everyone has that, we can make more data-driven decisions.
更好的可視化效果等同于對(duì)數(shù)據(jù)的更好理解-當(dāng)每個(gè)人都擁有數(shù)據(jù)時(shí),我們可以做出更多由數(shù)據(jù)驅(qū)動(dòng)的決策。
If you enjoyed, you may also enjoy 5 Tips to Stop Doing Pie Charts Wrong.
如果喜歡,您可能還會(huì)喜歡5停止做餅圖錯(cuò)誤的提示 。
翻譯自: https://medium.com/swlh/5-tips-to-stop-doing-bar-charts-wrong-3aac8e3bfcd6
d3 制作條形圖
總結(jié)
以上是生活随笔為你收集整理的d3 制作条形图_停止制作常见的坏条形图的5个简单技巧的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [html] 说说如果a链接href=
- 下一篇: 【时间序列】DTW算法详解