Gadfly for Julia,在条形图中绘制多个维度
Gadfly for Julia, plotting multiple dimension in Bar Chart
我对 Julia 语言的绘图包 Gadfly 有疑问。假设我有一个如下所示的 DataFrame:
DataFrame:(DrinkType, Country, Month, Sales)
Coke, UK, April, 500
Coke, US, April, 500
Coke, UK, March, 400
Coke, US, March, 700
我想为每个 DrinkType 生成一个条形图,其中英国或美国的颜色以闪避样式分为红色和绿色,每个国家/地区的三月和四月为浅绿色和浅红色(不透明颜色) ) 堆叠样式。
结果应该为每种饮料显示 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 个柱...
如果我对问题的理解正确,您可以使用
生成您正在寻找的图(减去不同月份的 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"))
或类似的,尽管此时条形图可能不是您的最佳选择。
我对 Julia 语言的绘图包 Gadfly 有疑问。假设我有一个如下所示的 DataFrame:
DataFrame:(DrinkType, Country, Month, Sales)
Coke, UK, April, 500
Coke, US, April, 500
Coke, UK, March, 400
Coke, US, March, 700
我想为每个 DrinkType 生成一个条形图,其中英国或美国的颜色以闪避样式分为红色和绿色,每个国家/地区的三月和四月为浅绿色和浅红色(不透明颜色) ) 堆叠样式。
结果应该为每种饮料显示 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 个柱...
如果我对问题的理解正确,您可以使用
生成您正在寻找的图(减去不同月份的 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"))
或类似的,尽管此时条形图可能不是您的最佳选择。