-
-
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 7 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,50 @@ | ||
# --------------------------------------------------------------------------- | ||
# Beeswarm plot | ||
@recipe function f(::Type{Val{:beeswarm}}, x, y, z; trim::Bool=false, side::Symbol=:both) | ||
if !(side in [:both :left :right]) | ||
BeastyBlacksmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
warn("side (you gave :$side) must be one of :both, :left, or :right") | ||
side = :both | ||
info("side set to :$side") | ||
end | ||
x, y = Float64[], Float64[] | ||
glabels = sort(collect(unique(x))) | ||
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. Part of the code here is identical across beeswarm, violin and boxplot - I haven't checked carefully, but would it not be possible to extract a general function? 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. Not sure yet -- I'll try to get the beeswarm function working, then see if we can extract some things. |
||
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) | ||
|
||
# Then we apply Sturge's rule to get the number of bins | ||
BeastyBlacksmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
n = convert(Int64, ceil(1+log2(length(lab_y)))) | ||
|
||
# Get the widths and the coordinates | ||
widths, centers = violin_coords(lab_y, trim=trim, n=n) | ||
isempty(widths) && continue | ||
|
||
# normalize | ||
hw = 0.5_cycle(bw, i) | ||
widths = hw * widths / Plots.ignorenan_maximum(widths) | ||
|
||
# make the violin | ||
xcenter = Plots.discrete_value!(d[:subplot][:xaxis], glabel)[1] | ||
if (side==:right) | ||
xcoords = vcat(widths, zeros(length(widths))) + xcenter | ||
elseif (side==:left) | ||
xcoords = vcat(zeros(length(widths)), -reverse(widths)) + xcenter | ||
else | ||
xcoords = vcat(widths, -reverse(widths)) + xcenter | ||
end | ||
ycoords = vcat(centers, reverse(centers)) | ||
|
||
push!(xsegs, xcoords) | ||
push!(ysegs, ycoords) | ||
end | ||
|
||
seriestype := :scatter | ||
x := xsegs.pts | ||
y := ysegs.pts | ||
() | ||
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.