美文网首页
Tableau制作延展条形图(不完整教程)

Tableau制作延展条形图(不完整教程)

作者: 大力SAMA | 来源:发表于2020-07-20 22:37 被阅读0次

    原教程 扫地sir https://www.jianshu.com/p/10c85365f976
    应用参考:https://public.tableau.com/profile/jiangbin#!/vizhome/ForbesListsoftheWorldsBestPaidAthletesInThePast30-Years/1

    这里把自己在按教程作图过程中遇到的问题和思考分享给大家٩(๑❛ᴗ❛๑)۶,主要是对数据的准备和Y计算字段的代码进行介绍,建议大家先看原教程,有些细节和步骤我就不补充了,因为我也是依葫芦画瓢。

    作图数据
    基础数据

    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
    

    辅助数据

    Path Id
    1
    2
    3
    4
    5
    6
    7
    8
    9
    

    教程中是利用tableau将这2个数据进行并集连接(如下图),不知道是版本问题还是能力问题,这步没搞定,所以我先在Excel里把数据准备好。


    数据准备
    第一步:把基础数据放入Excel表格,按逗号进行分列,结果如下


    第二步:补充Path Id

    第三步:利用power query逆透视,实现教程中的并集效果


    把属性列删除,数据就准备好啦(ノ´▽`)ノ♪

    参数说明

    参数说明
    60%的长度是在0值以上,40%的长度在0值以下
    创建参数X0=0;
    创建参数X1=-20%;
    创建参数X2=-40%;
    创建参数width=3;
    创建参数indentation=2;
    创建参数indentation1=4;
    width和indentation的差距越大,条形图之间的间距也越大。

    创建计算字段
    创建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
    

    创建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字段公式与教程一致

    Y字段公式调整
    感觉Y字段的公式有点太复杂了,所以尝试调整
    尝试一:
    创建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
    
    尝试一

    尝试一的结果是中间条形图右侧与0值线贴合,不够美观。

    尝试二:
    创建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
    
    尝试二

    这种方式结果与教程的结果相同,且公式更易理解。

    补充
    1、tableau格式修改

    2、不太明白的地方
    作图的时候首先用“多边形”这一标记类型完成了条形图的制作,但是在此类型下无法添加标签,因此利用双轴——>同步轴,再把标记类型改为“线”的“骚操作”,最终可以添加标签,这里不太明白。

    相关文章

      网友评论

          本文标题:Tableau制作延展条形图(不完整教程)

          本文链接:https://www.haomeiwen.com/subject/kokykktx.html