René
René

Reputation: 4827

Specify colors in a Gadfly (Julia) boxplot

I am trying to reproduce this Seaborn plot using Gadfly.

The code I have so far is:

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
        ), 
    )

I would like to specify the colors "green" and "purple" to match the Seaborn plot. Any suggestions how to do this in Gadfly?

Additional:

enter image description here

Upvotes: 2

Views: 215

Answers (1)

Bill
Bill

Reputation: 6086

You need to add a line with 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),
)

Upvotes: 1

Related Questions