在 Gadfly (Julia) 箱线图中指定颜色
Specify colors in a Gadfly (Julia) boxplot
我正在尝试使用 Gadfly 重现 this Seaborn 图。
我目前的代码是:
using CSV, DataFrames, Gadfly
download("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv", "tips.csv")
tips = DataFrame(CSV.File("tips.csv"));
plot(
tips,
x = :day,
y = :total_bill,
color = :smoker,
Geom.boxplot,
Scale.x_discrete(levels = ["Thur", "Fri", "Sat", "Sun"]),
Theme(
key_position = :top,
boxplot_spacing = 20px
),
)
我想指定颜色“绿色”和“紫色”以匹配 Seaborn 图。
有什么关于如何在 Gadfly 中执行此操作的建议吗?
其他:
- 如何设置
smoker
顺序从yes
到no
?
您需要添加一行 Scale.color_discrete_manual
:
using CSV, DataFrames, Gadfly
download(
"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv",
"tips.csv",
)
tips = DataFrame(CSV.File("tips.csv"));
plot(
tips,
x = :day,
y = :total_bill,
color = :smoker,
Geom.boxplot,
Scale.x_discrete(levels = ["Thur", "Fri", "Sat", "Sun"]),
Scale.color_discrete_manual("purple", "green", order=[2, 1]),
Theme(key_position = :top, boxplot_spacing = 20px),
)
我正在尝试使用 Gadfly 重现 this Seaborn 图。
我目前的代码是:
using CSV, DataFrames, Gadfly
download("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv", "tips.csv")
tips = DataFrame(CSV.File("tips.csv"));
plot(
tips,
x = :day,
y = :total_bill,
color = :smoker,
Geom.boxplot,
Scale.x_discrete(levels = ["Thur", "Fri", "Sat", "Sun"]),
Theme(
key_position = :top,
boxplot_spacing = 20px
),
)
我想指定颜色“绿色”和“紫色”以匹配 Seaborn 图。 有什么关于如何在 Gadfly 中执行此操作的建议吗?
其他:
- 如何设置
smoker
顺序从yes
到no
?
您需要添加一行 Scale.color_discrete_manual
:
using CSV, DataFrames, Gadfly
download(
"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv",
"tips.csv",
)
tips = DataFrame(CSV.File("tips.csv"));
plot(
tips,
x = :day,
y = :total_bill,
color = :smoker,
Geom.boxplot,
Scale.x_discrete(levels = ["Thur", "Fri", "Sat", "Sun"]),
Scale.color_discrete_manual("purple", "green", order=[2, 1]),
Theme(key_position = :top, boxplot_spacing = 20px),
)