Last active
June 29, 2017 11:35
-
-
Save cth/506339837c5cc475c2916e4195764fe1 to your computer and use it in GitHub Desktop.
plot similar to upset plots to visualize overlaps between sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A plot similar to upset plots to visualize overlaps between sets | |
using Plots | |
# Where does lines begin/end | |
function set_line!(set,vals,index) | |
start = stop = 0 | |
for i in 1:length(vals) | |
if vals[i] ∈ set | |
if start == 0 | |
start=i | |
end | |
stop=i | |
end | |
end | |
if start!=stop # they may be == 0, but it is not possible to only of them == 0 | |
plot!(Shape([(index,start),(index,stop)]), ) | |
end | |
end | |
function upsetplot(sets, setlabels) | |
inorder(set::Set) = [ elem for elem in set ] | |
vals = inorder(foldl(union,sets)) |> sort | |
println(vals) | |
x=reshape([ v ∈ s for v in vals for s in sets ], (length(sets), length(vals))) | |
w,h = size(x) | |
p=scatter([ (i,j) for i in 1:w for j in 1:h ], | |
color=[ x[i,j]?"black":"grey" for i in 1:w for j in 1:h ], | |
markersize=10, | |
yticks=(1:length(vals), vals), | |
xticks=(1:length(setlabels), setlabels), | |
top_margin=20mm, | |
right_margin=20mm, | |
xrotation=true, | |
border=false, | |
mirror=true, | |
legend=false, | |
grid=false) | |
for i in 1:length(sets) | |
set_line!(sets[i],vals,i) | |
end | |
p | |
end | |
# Example of usage: Visualizing overlaps between tree sets | |
s1=[Set(["a","b","c"]),Set(["c","d"]), Set(["a","d"])] | |
upsetplot(s1,["A","B","long name"]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment