[英]'stack order' in Gadfly histogram
When plotting a "stacked histogram", I would like the "stack order" to be the same as the legend order - Fair
(first / bottom) and Ideal
(last / top) - so that the colors are in order from light to dark.绘制“堆叠直方图”时,我希望“堆叠顺序”与图例顺序相同 - Fair
(第一/底部)和Ideal
(最后/顶部) - 以便颜色从浅到深. Like in this example.就像在这个例子中一样。
Any idea how to do that?知道怎么做吗? My code so far:到目前为止我的代码:
using CSV, DataFrames, Gadfly
download("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/diamonds.csv", "diamonds.csv")
diamonds = DataFrame(CSV.File("diamonds.csv"))
palette = ["#9D95C2", "#B4ADCF", "#C9C4DB", "#DFDCE9", "#F5F3F4"]
plot(
diamonds,
x = :price,
color = :cut,
Geom.histogram(bincount=50),
Scale.x_log10,
Scale.color_discrete_manual(palette..., order = [1, 2, 4, 3, 5]),
Theme(
background_color = "white",
bar_highlight = color("black")
),
)
This is actually not that easy.这实际上并不容易。 There is a somewhat related question at How do I sort a bar chart in ascending or descending order in Julia's Gadfly?在我如何在 Julia 的牛虻中按升序或降序对条形图进行排序? (Does anyone know a less hacky way?) I will probably try to fiddle a bit more, but what you can do is using levels on top of order. (有谁知道一种不那么老套的方法吗?)我可能会尝试更多地摆弄,但你可以做的是在顺序之上使用关卡。
Scale.color_discrete_manual(palette...,
levels = ["Fair", "Good", "Very Good", "Premium", "Ideal"]
order = [1, 2, 4, 3, 5]),
Then you have three lists, one for the colors one for the levels and one for the order.然后你有三个列表,一个用于颜色,一个用于级别,一个用于订单。 It is a nightmare, but there should be one permutation that looks similar to the seaborn example (I hope).这是一场噩梦,但应该有一个看起来类似于 seaborn 示例的排列(我希望如此)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.