How to draw one-line Venn diagram?
ref = StringSplit["A O I L D M E B C P K F N J H G Q"];
pos = PositionIndex[ref];
sorteddata = SortBy[pos@*First][SortBy[pos] /@ data];
Graphics[{Text[Style[#, 32], Append[pos@#, 0]] & /@ ref,
MapThread[{ Opacity[.5], #2, Disk[Append[Mean[pos /@ #], 0], {Length[#]/2, 1}]} &,
{sorteddata, ColorData[97] /@ Range[Length@data]}]}]
Alternatively,
Graphics[{Text[Style[#, FontSize -> Scaled[.05]], Append[pos@#, 0]] & /@ ref,
MapThread[{ Opacity[.5], #2, CapForm["Round"],
AbsoluteThickness[35], Line[Thread[{Flatten[MinMax[pos /@ #]], 0}]]} &,
{sorteddata, ColorData[97] /@ Range[Length@data]}]},
ImageSize -> 600]
Here's one way, which wraps elements in nested colored Frame
s depending on their set membership. It's not the prettiest, but it's easy and handles non-contiguous intersections straightforwardly.
data = {{"A"}, {"J"}, {"Q"}, {"G", "H"}, {"I", "O"}, {"B", "C", "E",
"F", "K", "N", "P"}, {"B", "C", "D", "E", "F", "K", "L", "M", "P"}};
elements = "A O I L D M E B C P K F N J H G Q" // StringSplit;
colors = AssociationThread[
data -> Map[ColorData[1], Range@Length@data]];
Row[KeyValueMap[
Function[{element, memberships},
Fold[Framed[#1, Background -> Lighter[#2], FrameStyle -> #2] &,
element, memberships]
],
AssociationMap[Select[data, MemberQ[#]] & /* Map[colors],
elements]]];