-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
WIP: Beeswarm plot #61
base: master
Are you sure you want to change the base?
Changes from 10 commits
7f09771
4d736a4
9c70d2d
3f360ed
9c2561a
1764bda
a3812da
d7d9396
066340e
5f8f8f1
bec231d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
@shorthands beeswarm | ||
|
||
# --------------------------------------------------------------------------- | ||
# Beeswarm plot | ||
@recipe function f(::Type{Val{:beeswarm}}, x, y, z; trim=false, side=:both) | ||
|
||
side = check_side(side) | ||
|
||
xp, yp = Float64[], Float64[] | ||
glabels = sort(collect(unique(x))) | ||
bw = d[:bar_width] | ||
bw == nothing && (bw = 0.8) | ||
|
||
for (i,glabel) in enumerate(glabels) | ||
# We get the values for this label | ||
lab_y = y[filter(i -> _cycle(x,i) == glabel, 1:length(y))] | ||
lab_x = zeros(lab_y) | ||
|
||
# Number of bins (defaults to sturges) | ||
binning_mode = d[:bins] | ||
if binning_mode == :auto | ||
binning_mode = :sturges | ||
end | ||
n = Plots._auto_binning_nbins(tuple(lab_y), 1, mode=binning_mode) | ||
|
||
# Get the widths and the coordinates | ||
widths, centers = StatPlots.violin_coords(lab_y, trim=trim, n=n) | ||
isempty(widths) && continue | ||
|
||
# normalize | ||
hw = 0.5Plots._cycle(bw, i) | ||
widths = hw * widths / Plots.ignorenan_maximum(widths) | ||
|
||
# make the violin | ||
xcenter = Plots.discrete_value!(d[:subplot][:xaxis], glabel)[1] | ||
|
||
for i in 2:length(centers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
inside = Bool[centers[i-1] < u <= centers[i] for u in lab_y] | ||
if sum(inside) > 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need if sum(inside) == 1
lab_x[inside] .+= xcenter
elseif sum(inside) > 1 for when there's only a single point. |
||
if (side==:right) | ||
start == 0.0 | ||
stop = widths[i] | ||
elseif (side==:left) | ||
start = -widths[i] | ||
stop = 0.0 | ||
elseif (side == :both) | ||
start = -widths[i] | ||
stop = widths[i] | ||
end | ||
lab_x[inside] = lab_x[inside] .+ linspace(start, stop, sum(inside)) .+ xcenter | ||
end | ||
end | ||
|
||
append!(xp, lab_x) | ||
append!(yp, lab_y) | ||
|
||
end | ||
|
||
x := xp | ||
y := yp | ||
seriestype := :scatter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, add if get!(d, :markershape, :circle) == :none
d[:markershape] = :circle
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cf JuliaPlots/Plots.jl#989 , a PR to fix this behaviour in Plots so this code won't be necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was merged so disregard this comment. |
||
() | ||
|
||
end | ||
|
||
Plots.@deps beeswarm scatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for also taking the time to clean up files etc. But I'd like to keep changes like this separate from changes that add new functionality - can you cherry-pick this and the other changes (deleted/insert lines) to a separate PR and keep this PR on the
beeswarm
recipe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit of the readme has been changed, so this can be scrapped when you rebase.