Pretty specific question: is it possible to align the boxplot and scatter components of a rainclouds plot and have them centered on the xticks with Makie.jl? Basically, I am looking to overlay a boxplot and jitter plot and this seems to be the only way to do so in Julia. I realize this is not necessarily the intended use-case of the rainclouds plot.
it would be easier to help you if you can show what’s the desired outcome (maybe a plot you’ve seen somewhere else), and also a runnable Makie example that you have tried.
Sure – I just tried the first example provided in the rainclouds page (https://docs.makie.org/stable/reference/plots/rainclouds/), and played around with the keyword arguments. Below is the code. Here is an example of what I am going for (I would prefer vertical rather than horizontal, but that’s a minor detail): Horizontal boxplot with observations — seaborn 0.13.2 documentation. Essentially, the difference is that the scatter points and boxes are centrally aligned (both to the x-ticks) in the latter case.
using CairoMakie
using Random
using Makie: rand_localized
####
#### Below is used for testing the plotting functionality.
####
function mockup_distribution(N)
all_possible_labels = ["Single Mode", "Double Mode", "Random Exp", "Uniform"]
category_type = rand(all_possible_labels)
if category_type == "Single Mode"
random_mean = rand_localized(0, 8)
random_spread_coef = rand_localized(0.3, 1)
data_points = random_spread_coef*randn(N) .+ random_mean
elseif category_type == "Double Mode"
random_mean = rand_localized(0, 8)
random_spread_coef = rand_localized(0.3, 1)
data_points = random_spread_coef*randn(Int(round(N/2.0))) .+ random_mean
random_mean = rand_localized(0, 8)
random_spread_coef = rand_localized(0.3, 1)
data_points = vcat(data_points, random_spread_coef*randn(Int(round(N/2.0))) .+ random_mean)
elseif category_type == "Random Exp"
data_points = randexp(N)
elseif category_type == "Uniform"
min = rand_localized(0, 4)
max = min + rand_localized(0.5, 4)
data_points = [rand_localized(min, max) for _ in 1:N]
else
error("Unidentified category.")
end
return data_points
end
function mockup_categories_and_data_array(num_categories; N = 500)
category_labels = String[]
data_array = Float64[]
for category_label in string.(('A':'Z')[1:min(num_categories, end)])
data_points = mockup_distribution(N)
append!(category_labels, fill(category_label, N))
append!(data_array, data_points)
end
return category_labels, data_array
end
category_labels, data_array = mockup_categories_and_data_array(3)
colors = Makie.wong_colors()
rainclouds(category_labels, data_array;
xlabel = "Categories of Distributions", ylabel = "Samples", title = "My Title",
plot_boxplots = false, cloud_width=0.5, clouds=hist, hist_bins=50,
color = colors[indexin(category_labels, unique(category_labels))])
what about actually use boxplot · Makie and scatter plot?
I would want the scatter plot to have random jitter (Scatterplot Jittering). This is also what the rainclouds plot does. I might be able to write up something to generate the jitter correctly, I was only wondering if it is possible to do this using functions already written in the Makie package.
GitHub - asinghvi17/SwarmMakie.jl: Beeswarm plots for Makie.jl! should be able to give you a jittered scatter plot which you can plot separately from the boxplot - see e.g. Uniform jitter
very cool, thanks!