Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add raincloud plots from Beacon Biosignals #1725

Merged
merged 22 commits into from Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -2,6 +2,8 @@

## master

- Added `rainclouds` and `raindclouds!` [#1725](https://github.com/JuliaPlots/Makie.jl/pull/1725)
SimonDanisch marked this conversation as resolved.
Show resolved Hide resolved

## v0.17.1
- Added word wrapping. In `Label`, `word_wrap = true` causes it to use the suggested width and wrap text to fit. In `text`, `word_wrap_width > 0` can be used to set a pixel unit line width. Any word (anything between two spaces without a newline) that goes beyond this width gets a newline inserted before it. [#1819](https://github.com/JuliaPlots/Makie.jl/pull/1819)
- Improved `Axis3`'s interactive performance. [#1835](https://github.com/JuliaPlots/Makie.jl/pull/1835)
Expand Down
183 changes: 183 additions & 0 deletions docs/examples/plotting_functions/rainclouds.md
@@ -0,0 +1,183 @@

# raincloud

{{doc rainclouds}}

\begin{examplefigure}{}
```julia
using CairoMakie
CairoMakie.activate!(type = "png")
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", "Single Mode", "Double Mode",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it intentional that single mode and double mode show up twice here?

"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

Comment on lines +27 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

potential duplication? otherwise these variables get overridden immediately

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right to me. (Note the vcat on line 33).

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()
fig = 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))])
fig
```
\end{examplefigure}


\begin{examplefigure}{}
```julia
fig = rainclouds(category_labels, data_array;
xlabel = "Categories of Distributions",
ylabel = "Samples", title = "My Title",
plot_boxplots = true, cloud_width=0.5, clouds=hist,
color = colors[indexin(category_labels, unique(category_labels))])
fig
```
\end{examplefigure}


\begin{examplefigure}{}
```julia
fig = rainclouds(category_labels, data_array;
xlabel = "Categories of Distributions", ylabel = "Samples", title = "My Title",
plot_boxplots = true, cloud_width=0.5, side = :right,
color = colors[indexin(category_labels, unique(category_labels))])
fig
```
\end{examplefigure}

\begin{examplefigure}{}
```julia
more_category_labels, more_data_array = mockup_categories_and_data_array(6)

fig = rainclouds(more_category_labels, more_data_array;
xlabel = "Categories of Distributions", ylabel = "Samples", title = "My Title",
plot_boxplots = true, cloud_width=0.5,
color = colors[indexin(more_category_labels, unique(more_category_labels))])
```
\end{examplefigure}

\begin{examplefigure}{}
```julia
category_labels, data_array = mockup_categories_and_data_array(6)
fig = rainclouds(category_labels, data_array;
xlabel = "Categories of Distributions",
ylabel = "Samples", title = "My Title",
plot_boxplots = true, cloud_width=0.5,
color = colors[indexin(category_labels, unique(category_labels))])
```
\end{examplefigure}

4 of these, between 3 distributions
Left and Right example
With and Without Box Plot

\begin{examplefigure}{}
```julia
fig = Figure(resolution = (800*2, 600*5))
colors = [Makie.wong_colors(); Makie.wong_colors()]

category_labels, data_array = mockup_categories_and_data_array(3)
rainclouds!(Axis(fig[1, 1]), category_labels, data_array;
title = "Left Side, with Box Plot",
side = :left,
plot_boxplots = true,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[2, 1]), category_labels, data_array;
title = "Left Side, without Box Plot",
side = :left,
plot_boxplots = false,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[1, 2]), category_labels, data_array;
title = "Right Side, with Box Plot",
side = :right,
plot_boxplots = true,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[2, 2]), category_labels, data_array;
title = "Right Side, without Box Plot",
side = :right,
plot_boxplots = false,
color = colors[indexin(category_labels, unique(category_labels))])

# Plots wiht more categories
# dist_between_categories (0.6, 1.0)
# with and without clouds

category_labels, data_array = mockup_categories_and_data_array(12)
rainclouds!(Axis(fig[3, 1:2]), category_labels, data_array;
title = "More categories. Default spacing.",
plot_boxplots = true,
dist_between_categories = 1.0,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[4, 1:2]), category_labels, data_array;
title = "More categories. Adjust space. (smaller cloud widths and smaller category distances)",
plot_boxplots = true,
cloud_width = 0.3,
dist_between_categories = 0.5,
color = colors[indexin(category_labels, unique(category_labels))])


rainclouds!(Axis(fig[5, 1:2]), category_labels, data_array;
title = "More categories. Adjust space. No clouds.",
plot_boxplots = true,
clouds = nothing,
dist_between_categories = 0.5,
color = colors[indexin(category_labels, unique(category_labels))])

supertitle = Label(fig[0, :], "Cloud Plot Testing (Scatter, Violin, Boxplot)", textsize=30)
fig
```
\end{examplefigure}
1 change: 1 addition & 0 deletions src/Makie.jl
Expand Up @@ -290,6 +290,7 @@ end
include("figureplotting.jl")
include("basic_recipes/series.jl")
include("basic_recipes/text.jl")
include("basic_recipes/raincloud.jl")

export Heatmap, Image, Lines, LineSegments, Mesh, MeshScatter, Scatter, Surface, Text, Volume
export heatmap, image, lines, linesegments, mesh, meshscatter, scatter, surface, text, volume
Expand Down