Skip to content

Instantly share code, notes, and snippets.

@cth
Last active June 29, 2017 11:35
Show Gist options
  • Save cth/506339837c5cc475c2916e4195764fe1 to your computer and use it in GitHub Desktop.
Save cth/506339837c5cc475c2916e4195764fe1 to your computer and use it in GitHub Desktop.
plot similar to upset plots to visualize overlaps between sets
# 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