我对朱莉娅语言的绘图包Gadfly有疑问。假设我有一个看起来像这样的DataFrame:
DataFrame:(DrinkType, Country, Month, Sales)
Coke, UK, April, 500
Coke, US, April, 500
Coke, UK, March, 400
Coke, US, March, 700
我想为每个DrinkType生成一个条形图,其中颜色分为红色和绿色,英国或美国为躲闪样式,而月份3月和4月为每个国家为浅绿色和浅红色(不透明颜色)叠加的风格。
结果应该显示每个饮料2个酒吧,如:
Coke: bar1, stacked US(400 March (light red), 500 April (red))
bar2, stacked UK(700 March (light greed), 500 April (green))
到目前为止,我已经想出了这个:
t0 = plot(result, y=:Drink, x=:x1, color=:Country, Theme(minor_label_font_size= 12pt, bar_spacing = -0.15cm), Geom.bar(position=:dodge, orientation=:horizontal)
,Scale.color_discrete_manual(Green,Orange),
Guide.title("Overall Drink Trends") , Guide.ylabel(nothing),Guide.xlabel(nothing))
这将分别生成4个柱...
答案 0 :(得分:3)
如果我理解正确的问题,您可以使用
生成您正在寻找的图表(减去不同月份的Alpha值的变化)using DataFrames, Gadfly
data = DataFrame()
data[:DrinkType] =["Coke","Coke","Coke","Coke","Pepsi","Pepsi","Pepsi","Pepsi"]
data[:Country] = ["UK", "US", "UK", "US","UK", "US", "UK", "US"]
data[:Month] = ["April", "April", "March", "March","April", "April", "March", "March"]
data[:Sales] = [500,500,400,700,340,120,990,620]
data
如果你还想显示另一个维度,一种方法是使用像
这样的子图格plot(data, xgroup="DrinkType", x="Month", y="Sales", color="Country", Geom.subplot_grid(Geom.bar(position=:dodge)),Scale.color_discrete_manual("red","green"))
或
plot(data, xgroup="Country", x="Month", y="Sales", color="DrinkType", Geom.subplot_grid(Geom.bar(position=:stack)),Scale.color_discrete_manual("red","green"))
或类似,虽然此时条形图可能不是您的最佳选择。