用Tableau画华夫饼图

2019-09-26  本文已影响0人  扫地sir

在Tableau中画华夫饼图是比较简单的,主要是两个步骤,第一步确定华夫饼图中的100个点的位置,第二步是通过计算字段给点着色。

建立数据集

Percentage,X,Y,X(circle),Y(circle)
0.01,1,1,0.028242565,-0.909326316
0.02,2,1,-0.151807065,-0.897009814
0.03,3,1,-0.325882963,-0.849395247
0.04,4,1,0.196417528,-0.843853057
0.05,5,1,0.376219116,-0.828330349
0.06,6,1,-0.487135102,-0.768356286
0.07,7,1,0.055628541,-0.730945897
0.08,8,1,0.556330777,-0.71983441
0.09,9,1,-0.124449881,-0.718608186
0.1,10,1,-0.300557991,-0.670710577
0.11,1,2,-0.629218079,-0.657081882
0.12,2,2,0.390576806,-0.648431983
0.13,3,2,0.210400785,-0.638128237
0.14,4,2,-0.46181013,-0.589671617
0.15,5,2,0.699642243,-0.581526201
0.16,6,2,-0.002368663,-0.560048589
0.17,7,2,-0.181147055,-0.535393934
0.18,8,2,0.526700981,-0.52994243
0.19,9,2,-0.746540814,-0.519950771
0.2,10,2,0.309412101,-0.487243099
0.21,1,3,-0.342399194,-0.454354974
0.22,2,3,0.136036209,-0.435678324
0.23,3,3,0.800665249,-0.431980496
0.24,4,3,-0.519022821,-0.415733579
0.25,5,3,-0.037115589,-0.382954782
0.26,6,3,0.627723988,-0.380396725
0.27,7,3,0.445561267,-0.368692899
0.28,8,3,-0.686961444,-0.349598594
0.29,9,3,-0.210121103,-0.331581053
0.3,10,3,0.267253981,-0.311765869
0.31,1,4,-0.859747928,-0.297498724
0.32,2,4,-0.382586097,-0.278415841
0.33,3,4,0.094518727,-0.259496399
0.34,4,4,0.758867475,-0.256417085
0.35,5,4,-0.555321351,-0.226146371
0.36,6,4,-0.078216527,-0.207226929
0.37,7,4,0.578409283,-0.206794809
0.38,8,4,0.398888297,-0.188307486
0.39,9,4,-0.728234875,-0.173911175
0.4,10,4,-0.250951781,-0.154957458
0.41,1,5,0.898584967,-0.142186669
0.42,2,5,0.226153043,-0.136038016
0.43,3,5,-0.901724677,-0.120642403
0.44,4,5,-0.423687035,-0.102687988
0.45,5,5,0.053417789,-0.083768546
0.46,6,5,0.710260015,-0.082615818
0.47,7,5,-0.596422289,-0.050418518
0.48,8,5,-0.119317465,-0.031499075
0.49,9,5,0.537308345,-0.031066956
0.5,10,5,0.357787359,-0.012579633
0.51,1,6,-0.769155158,0.001858834
0.52,2,6,-0.292052719,0.020770395
0.53,3,6,0.908971485,0.037984599
0.54,4,6,0.185052105,0.039689837
0.55,5,6,-0.464787973,0.073039865
0.56,6,6,0.012316851,0.091959308
0.57,7,6,0.737983031,0.095712531
0.58,8,6,-0.901145269,0.12493676
0.59,9,6,-0.638298106,0.126140762
0.6,10,6,-0.160418403,0.144228778
0.61,1,7,0.56331773,0.147519375
0.62,2,7,0.316686421,0.16314822
0.63,3,7,-0.333153657,0.196498248
0.64,4,7,0.143951167,0.215417691
0.65,5,7,0.882207861,0.222188367
0.66,6,7,-0.505888911,0.248767718
0.67,7,7,-0.028784087,0.267687161
0.68,8,7,0.694952046,0.270977758
0.69,9,7,0.448320737,0.286606603
0.7,10,7,-0.858753325,0.30035765
0.71,1,8,-0.678291568,0.302123967
0.72,2,8,-0.201519341,0.319956631
0.73,3,8,0.275585483,0.338876073
0.74,4,8,-0.374254595,0.372226101
0.75,5,8,0.102850229,0.391145544
0.76,6,8,0.813717192,0.406861552
0.77,7,8,0.579955053,0.410064986
0.78,8,8,-0.546657252,0.42558235
0.79,9,8,-0.069885025,0.443415014
0.8,10,8,0.407219799,0.462334456
0.81,1,9,-0.782568739,0.463959222
0.82,2,9,-0.242620279,0.495684484
0.83,3,9,0.234484545,0.514603927
0.84,4,9,0.717395668,0.559477834
0.85,5,9,0.061749291,0.566873397
0.86,6,9,-0.447754332,0.576538562
0.87,7,9,-0.642899503,0.578248635
0.88,8,9,0.538854115,0.585792839
0.89,9,9,-0.116897126,0.625242328
0.9,10,9,0.366118861,0.63806231
0.91,1,10,-0.292793093,0.669040344
0.92,2,10,0.2060071,0.721331688
0.93,3,10,-0.543996583,0.729204847
0.94,4,10,0.026960827,0.743959049
0.95,5,10,0.497753177,0.761520693
0.96,6,10,-0.389353861,0.822238142
0.97,7,10,-0.209005784,0.828881679
0.98,8,10,0.337641416,0.844790071
0.99,9,10,0.157204922,0.896067639
1,10,10,-0.047070261,0.908546301

为了大家方便,我给大家提供一个100个点的数据集,Percentage就是百分比,X、Y是方形华夫饼图的点坐标,X(circle)、Y(circle)是圆形华夫饼图的点坐标

下面的数据就根据自身需求了,我随意编了几个

Category,Value
A,10.10%
B,20.50%
C,90%

然后需要将两个数据集引入Tableau进行内连接,这里有个小技巧,因为两个数据集没有相同的字段,所以Tableau会报错。

这时我们需要给两个数据集创建联接计算。

创建联接计算,"link"

这样两个数据集就可以联接到一起了

这样做省去了,在数据集里增加link字段的过程,很实用。现在数据集是300行,A、B、C各100行。

开始画图

首先创建一个计算字段

其实写成[Value]>=[Percentage],也是可以的,因为是行级别的计算,每个点对应了1行数据,所以计算也是没有问题的。
有时候根据需求也可以调整一下,比如百分比需要四舍五入一下,ROUND(AVG([Value]),2)>=AVG([Percentage]),这样例子中的B=20.50%就会显示21个点。

当然也可以把X、Y换成X(circle)、Y(circle),做成圆形的华夫饼图。

最后再突出一下百分比

好了,上面的教程很简单,给大家介绍一个Andy大神的华夫饼图的例子,YouTube视频里面有好多小细节、小技巧非常详细且实用,建议学习。

https://public.tableau.com/profile/andy.kriebel#!/vizhome/HowtoCreateaWaffleChartUsingDataDensification/Example

此篇文章已发布到我的公众号:saodisir,有兴趣也可关注一下

上一篇下一篇

猜你喜欢

热点阅读