原教程 掃地sir http://www.reibang.com/p/10c85365f976
應(yīng)用參考:https://public.tableau.com/profile/jiangbin#!/vizhome/ForbesListsoftheWorldsBestPaidAthletesInThePast30-Years/1
這里把自己在按教程作圖過程中遇到的問題和思考分享給大家?(?????)?薇缅,主要是對數(shù)據(jù)的準(zhǔn)備和Y計算字段的代碼進行介紹婿着,建議大家先看原教程命锄,有些細(xì)節(jié)和步驟我就不補充了瓶逃,因為我也是依葫蘆畫瓢杨伙。
作圖數(shù)據(jù)
基礎(chǔ)數(shù)據(jù)
Shape ID,Sub-Category,Values,n,Max_Values
1,Phones,105341,-6,105341
2,Chairs,95554,-5,105341
3,Binders,72788,-4,105341
4,Storage,69678,-3,105341
5,Copiers,62899,-2,105341
6,Tables,60894,-1,105341
7,Accessories,59946,0,105341
8,Machines,43545,1,105341
9,Appliances,42927,2,105341
10,Bookcases,30024,3,105341
11,Furnishings,28915,4,105341
12,Paper,27695,5,105341
13,Supplies,16049,6,105341
輔助數(shù)據(jù)
Path Id
1
2
3
4
5
6
7
8
9
教程中是利用tableau將這2個數(shù)據(jù)進行并集連接(如下圖)鲁冯,不知道是版本問題還是能力問題胯府,這步?jīng)]搞定铝阐,所以我先在Excel里把數(shù)據(jù)準(zhǔn)備好拖刃。
數(shù)據(jù)準(zhǔn)備
第一步:把基礎(chǔ)數(shù)據(jù)放入Excel表格删壮,按逗號進行分列,結(jié)果如下
第二步:補充Path Id
第三步:利用power query逆透視序调,實現(xiàn)教程中的并集效果
把屬性列刪除醉锅,數(shù)據(jù)就準(zhǔn)備好啦(?′▽`)??
參數(shù)說明
60%的長度是在0值以上,40%的長度在0值以下
創(chuàng)建參數(shù)X0=0发绢;
創(chuàng)建參數(shù)X1=-20%硬耍;
創(chuàng)建參數(shù)X2=-40%;
創(chuàng)建參數(shù)width=3边酒;
創(chuàng)建參數(shù)indentation=2经柴;
創(chuàng)建參數(shù)indentation1=4;
width和indentation的差距越大墩朦,條形圖之間的間距也越大坯认。
創(chuàng)建計算字段
創(chuàng)建X
case [Path ID]
when 1 then [X1]*[Max Values]
when 2 then [X2]*[Max Values]
when 3 then [X2]*[Max Values]
when 4 then [X1]*[Max Values]
when 5 then [X0]*[Max Values]
when 6 then (1+[X2])*[Values]
when 7 then (1+[X2])*[Values]
when 8 then [X0]*[Max Values]
when 9 then [X1]*[Max Values]
end
創(chuàng)建Y
case [Path ID]
when 1 then [N]*[indentation1]+[width]/[indentation]
when 2 then [N]*[indentation1]+[width]/[indentation]
when 3 then [N]*[indentation1]-[width]/[indentation]
when 4 then [N]*[indentation1]-[width]/[indentation]
when 5 then [N]*[indentation]-[width]/[indentation1]
when 6 then [N]*[indentation]-[width]/[indentation1]
when 7 then [N]*[indentation]+[width]/[indentation1]
when 8 then [N]*[indentation]+[width]/[indentation1]
when 9 then [N]*[indentation1]+[width]/[indentation]
end
Y字段公式調(diào)整
感覺Y字段的公式有點太復(fù)雜了,所以嘗試調(diào)整
嘗試一:
創(chuàng)建Y
case [Path ID]
when 1 then [N]*[indentation1]
when 2 then [N]*[indentation1]
when 3 then [N]*[indentation1]-[width]
when 4 then [N]*[indentation1]-[width]
when 5 then [N]*[indentation]-[width]/2
when 6 then [N]*[indentation]-[width]/2
when 7 then [N]*[indentation]
when 8 then [N]*[indentation]
when 9 then [N]*[indentation1]
end
嘗試一的結(jié)果是中間條形圖右側(cè)與0值線貼合氓涣,不夠美觀牛哺。
嘗試二:
創(chuàng)建Y
case [Path ID]
when 1 then [N]*[indentation1]+(1/2)*[width]
when 2 then [N]*[indentation1]+(1/2)*[width]
when 3 then [N]*[indentation1]-(1/2)*[width]
when 4 then [N]*[indentation1]-(1/2)*[width]
when 5 then [N]*[indentation]-(1/4)*[width]
when 6 then [N]*[indentation]-(1/4)*[width]
when 7 then [N]*[indentation]+(1/4)*[width]
when 8 then [N]*[indentation]+(1/4)*[width]
when 9 then [N]*[indentation1]+(1/2)*[width]
end
這種方式結(jié)果與教程的結(jié)果相同,且公式更易理解劳吠。
補充
1引润、tableau格式修改
2、不太明白的地方
作圖的時候首先用“多邊形”這一標(biāo)記類型完成了條形圖的制作痒玩,但是在此類型下無法添加標(biāo)簽淳附,因此利用雙軸——>同步軸议慰,再把標(biāo)記類型改為“線”的“騷操作”,最終可以添加標(biāo)簽奴曙,這里不太明白别凹。