我有一个这样的数据集:
| Name | 2017 | 2018 |
-----------------------
| Alice | 12 | 15 |
| Bob | 11 | 10 |
我想用水平堆叠条形图来绘制它,这样在 Y 轴上有 Alice 和 Bob,在 X 轴上有表格中的数字(Alice 的条形有 12 和 15 的比例长度,对于 Bob 来说也是如此) )。
我尝试先获取 2017 年的数据,所以我这么做了
using DataFrames, Gadfly
df = readtable("a.csv")
plot(df, x="2017", Geom.bar)
其中 a.csv
是
Name,2017,2018
Alice,12,15
Bob,11,10
但是我得到了
Error showing value of type Gadfly.Plot:
ERROR: UndefVarError: unshift! not defined
我也尝试过
plot(df, x="2017", y="Name", Geom.bar)
得到了
Error showing value of type Gadfly.Plot:
ERROR: MethodError: no method matching zero(::Type{String})
这里的问题似乎在于 Y 轴上的数据不是数字。
我有 Julia 0.6.2。
最佳答案
你可以这样做
df_tr = stack(df, [:x2017,:x2018])
Gadfly.plot(df_tr, color = "variable", x="value", y="Name",
Geom.bar(position=:stack, orientation= :horizontal))
我有这样的东西:
关于julia - 使用非数值轴绘制数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49939769/