I have a somewhat complex figure in tikz.
You'll notice there are two colors (they look red and green to me, but I'm told they are distinguishable to color-blind people: if you're color blind and they aren't different, please tell me). I would like to draw an appropriately-shapped node that encloses all of the circles that contain two red and two green with the central node red, and another that encloses all the circles with two red and two green and the central node is green. I want these nodes to not intersect or contain any other nodes.
Here is the code I've used to create my figure.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, backgrounds, fit, arrows, arrows.meta}
\definecolor{colorS}{RGB}{0,154,128}
\definecolor{colorI}{RGB}{255,32,0}
\tikzstyle{SusCirc}=[circle,draw=black!50,fill=colorS!90,thick, minimum size=2mm, inner sep = 0mm]%a circle
%representing a susceptible individual
\tikzstyle{InfCirc}=[circle,draw=black!50,fill=colorI!90,thick, minimum size=2mm, inner sep = 0mm]%a circle
%representing an infected individual
\tikzstyle{BigCirc}=[circle,draw=black!50,thick,inner sep=0pt,minimum size=0pt, inner sep = 0mm]
\begin{document}
\begin{tikzpicture}
\coordinate (top) at (0.000000,0.2500000);
\coordinate (left) at (-0.2165,-0.1250000);
\coordinate (right) at (0.2165,-0.1250000);
\coordinate (center) at (0,0);
\coordinate (SSSSloc) at (10.000000, 0.000000);
\node[SusCirc, minimum size = 2mm] (SSSScenter) at ($(SSSSloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (SSSSleft) at ($(SSSSloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (SSSStop) at ($(SSSSloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (SSSSright) at ($(SSSSloc)+(right)$) {};
\draw [-] (SSSScenter) -- (SSSSleft);
\draw [-] (SSSScenter) -- (SSSStop);
\draw [-] (SSSScenter) -- (SSSSright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SSSScenter)(SSSSleft)(SSSStop)(SSSSright)] (SSSS) at (SSSSloc) {};
\end{pgfonlayer}
\coordinate (SSSIloc) at (8.349598, 2.05150);
\node[SusCirc, minimum size = 2mm] (SSSIcenter) at ($(SSSIloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (SSSIleft) at ($(SSSIloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (SSSItop) at ($(SSSIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (SSSIright) at ($(SSSIloc)+(right)$) {};
\draw [-] (SSSIcenter) -- (SSSIleft);
\draw [-] (SSSIcenter) -- (SSSItop);
\draw [-] (SSSIcenter) -- (SSSIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SSSIcenter)(SSSIleft)(SSSItop)(SSSIright)] (SSSI) at (SSSIloc) {};
\end{pgfonlayer}
\coordinate (SSISloc) at (7.109723, 1.3464);%+0.2
\node[SusCirc, minimum size = 2mm] (SSIScenter) at ($(SSISloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (SSISleft) at ($(SSISloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (SSIStop) at ($(SSISloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (SSISright) at ($(SSISloc)+(right)$) {};
\draw [-] (SSIScenter) -- (SSISleft);
\draw [-] (SSIScenter) -- (SSIStop);
\draw [-] (SSIScenter) -- (SSISright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SSIScenter)(SSISleft)(SSIStop)(SSISright)] (SSIS) at (SSISloc) {};
\end{pgfonlayer}
\coordinate (SSIIloc) at (4.911270, 2.8868);
\node[SusCirc, minimum size = 2mm] (SSIIcenter) at ($(SSIIloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (SSIIleft) at ($(SSIIloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (SSIItop) at ($(SSIIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (SSIIright) at ($(SSIIloc)+(right)$) {};
\draw [-] (SSIIcenter) -- (SSIIleft);
\draw [-] (SSIIcenter) -- (SSIItop);
\draw [-] (SSIIcenter) -- (SSIIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SSIIcenter)(SSIIleft)(SSIItop)(SSIIright)] (SSII) at (SSIIloc) {};
\end{pgfonlayer}
\coordinate (SISSloc) at (7.059278, -1.007567); %-0.2
\node[SusCirc, minimum size = 2mm] (SISScenter) at ($(SISSloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (SISSleft) at ($(SISSloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (SISStop) at ($(SISSloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (SISSright) at ($(SISSloc)+(right)$) {};
\draw [-] (SISScenter) -- (SISSleft);
\draw [-] (SISScenter) -- (SISStop);
\draw [-] (SISScenter) -- (SISSright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SISScenter)(SISSleft)(SISStop)(SISSright)] (SISS) at (SISSloc) {};
\end{pgfonlayer}
\coordinate (SISIloc) at (4.955251, 1.31373);
\node[SusCirc, minimum size = 2mm] (SISIcenter) at ($(SISIloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (SISIleft) at ($(SISIloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (SISItop) at ($(SISIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (SISIright) at ($(SISIloc)+(right)$) {};
\draw [-] (SISIcenter) -- (SISIleft);
\draw [-] (SISIcenter) -- (SISItop);
\draw [-] (SISIcenter) -- (SISIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SISIcenter)(SISIleft)(SISItop)(SISIright)] (SISI) at (SISIloc) {};
\end{pgfonlayer}
\coordinate (SIISloc) at (3.473197, 0.17413);
\node[SusCirc, minimum size = 2mm] (SIIScenter) at ($(SIISloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (SIISleft) at ($(SIISloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (SIIStop) at ($(SIISloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (SIISright) at ($(SIISloc)+(right)$) {};
\draw [-] (SIIScenter) -- (SIISleft);
\draw [-] (SIIScenter) -- (SIIStop);
\draw [-] (SIIScenter) -- (SIISright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SIIScenter)(SIISleft)(SIIStop)(SIISright)] (SIIS) at (SIISloc) {};
\end{pgfonlayer}
\coordinate (SIIIloc) at (1.487967, 2.03170);
\node[SusCirc, minimum size = 2mm] (SIIIcenter) at ($(SIIIloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (SIIIleft) at ($(SIIIloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (SIIItop) at ($(SIIIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (SIIIright) at ($(SIIIloc)+(right)$) {};
\draw [-] (SIIIcenter) -- (SIIIleft);
\draw [-] (SIIIcenter) -- (SIIItop);
\draw [-] (SIIIcenter) -- (SIIIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (SIIIcenter)(SIIIleft)(SIIItop)(SIIIright)] (SIII) at (SIIIloc) {};
\end{pgfonlayer}
\coordinate (ISSSloc) at (8.323451, -1.79198);
\node[InfCirc, minimum size = 2mm] (ISSScenter) at ($(ISSSloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (ISSSleft) at ($(ISSSloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (ISSStop) at ($(ISSSloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (ISSSright) at ($(ISSSloc)+(right)$) {};
\draw [-] (ISSScenter) -- (ISSSleft);
\draw [-] (ISSScenter) -- (ISSStop);
\draw [-] (ISSScenter) -- (ISSSright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (ISSScenter)(ISSSleft)(ISSStop)(ISSSright)] (ISSS) at (ISSSloc) {};
\end{pgfonlayer}
\coordinate (ISSIloc) at (6.478631, 0.190366);
\node[InfCirc, minimum size = 2mm] (ISSIcenter) at ($(ISSIloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (ISSIleft) at ($(ISSIloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (ISSItop) at ($(ISSIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (ISSIright) at ($(ISSIloc)+(right)$) {};
\draw [-] (ISSIcenter) -- (ISSIleft);
\draw [-] (ISSIcenter) -- (ISSItop);
\draw [-] (ISSIcenter) -- (ISSIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (ISSIcenter)(ISSIleft)(ISSItop)(ISSIright)] (ISSI) at (ISSIloc) {};
\end{pgfonlayer}
\coordinate (ISISloc) at (5.037411, -0.94354);
\node[InfCirc, minimum size = 2mm] (ISIScenter) at ($(ISISloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (ISISleft) at ($(ISISloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (ISIStop) at ($(ISISloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (ISISright) at ($(ISISloc)+(right)$) {};
\draw [-] (ISIScenter) -- (ISISleft);
\draw [-] (ISIScenter) -- (ISIStop);
\draw [-] (ISIScenter) -- (ISISright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (ISIScenter)(ISISleft)(ISIStop)(ISISright)] (ISIS) at (ISISloc) {};
\end{pgfonlayer}
\coordinate (ISIIloc) at (2.797099, 1.3294); %+0.2
\node[InfCirc, minimum size = 2mm] (ISIIcenter) at ($(ISIIloc)+(center)$) {};
\node[SusCirc, minimum size = 2mm] (ISIIleft) at ($(ISIIloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (ISIItop) at ($(ISIIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (ISIIright) at ($(ISIIloc)+(right)$) {};
\draw [-] (ISIIcenter) -- (ISIIleft);
\draw [-] (ISIIcenter) -- (ISIItop);
\draw [-] (ISIIcenter) -- (ISIIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (ISIIcenter)(ISIIleft)(ISIItop)(ISIIright)] (ISII) at (ISIIloc) {};
\end{pgfonlayer}
\coordinate (IISSloc) at (5.071966, -2.5883046);
\node[InfCirc, minimum size = 2mm] (IISScenter) at ($(IISSloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (IISSleft) at ($(IISSloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (IISStop) at ($(IISSloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (IISSright) at ($(IISSloc)+(right)$) {};
\draw [-] (IISScenter) -- (IISSleft);
\draw [-] (IISScenter) -- (IISStop);
\draw [-] (IISScenter) -- (IISSright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (IISScenter)(IISSleft)(IISStop)(IISSright)] (IISS) at (IISSloc) {};
\end{pgfonlayer}
\coordinate (IISIloc) at (2.951006, -1.02703);%-0.2
\node[InfCirc, minimum size = 2mm] (IISIcenter) at ($(IISIloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (IISIleft) at ($(IISIloc)+(left)$) {};
\node[SusCirc, minimum size = 2mm] (IISItop) at ($(IISIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (IISIright) at ($(IISIloc)+(right)$) {};
\draw [-] (IISIcenter) -- (IISIleft);
\draw [-] (IISIcenter) -- (IISItop);
\draw [-] (IISIcenter) -- (IISIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (IISIcenter)(IISIleft)(IISItop)(IISIright)] (IISI) at (IISIloc) {};
\end{pgfonlayer}
\coordinate (IIISloc) at (1.725861, -1.81121);
\node[InfCirc, minimum size = 2mm] (IIIScenter) at ($(IIISloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (IIISleft) at ($(IIISloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (IIIStop) at ($(IIISloc)+(top)$) {};
\node[SusCirc, minimum size = 2mm] (IIISright) at ($(IIISloc)+(right)$) {};
\draw [-] (IIIScenter) -- (IIISleft);
\draw [-] (IIIScenter) -- (IIIStop);
\draw [-] (IIIScenter) -- (IIISright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (IIIScenter)(IIISleft)(IIIStop)(IIISright)] (IIIS) at (IIISloc) {};
\end{pgfonlayer}
\coordinate (IIIIloc) at (0.000000, 0.000000);
\node[InfCirc, minimum size = 2mm] (IIIIcenter) at ($(IIIIloc)+(center)$) {};
\node[InfCirc, minimum size = 2mm] (IIIIleft) at ($(IIIIloc)+(left)$) {};
\node[InfCirc, minimum size = 2mm] (IIIItop) at ($(IIIIloc)+(top)$) {};
\node[InfCirc, minimum size = 2mm] (IIIIright) at ($(IIIIloc)+(right)$) {};
\draw [-] (IIIIcenter) -- (IIIIleft);
\draw [-] (IIIIcenter) -- (IIIItop);
\draw [-] (IIIIcenter) -- (IIIIright);
\begin{pgfonlayer}{background}
\node[BigCirc, fit = (IIIIcenter)(IIIIleft)(IIIItop)(IIIIright)] (IIII) at (IIIIloc) {};
\end{pgfonlayer}
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (ISSS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (SSSI);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (SSIS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (SISS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SSSI.240) -- (ISSI.30);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSI) -- (SSII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSI) -- (SISI);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SSIS.210) -- (ISIS.70);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSIS) -- (SSII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSIS) -- (SIIS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SSII) -- (ISII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSII) -- (SIII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SISS) -- (IISS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SISS.150) -- (SISI.290);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SISS) -- (SIIS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SISI.250) -- (IISI.30);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SISI) -- (SIII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SIIS.200) -- (IIIS.70);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SIIS.160) -- (SIII.290);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SIII) -- (IIII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSS.110) -- (ISSI.330);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSS) -- (ISIS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSS) -- (IISS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSI) -- (ISII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSI) -- (IISI);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISIS.110) -- (ISII.330);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISIS) -- (IIIS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISII) -- (IIII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IISS) -- (IISI);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IISS) -- (IIIS);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IISI) -- (IIII);
\draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IIIS) -- (IIII);
\end{tikzpicture}
\end{document}
Is it doable to draw such a node? Ideally I'd like to be able to fill it with another color and I'd like it to not require a lot of fiddling.
Comment on why i'm doing this. I have the initial figure. I'm then showing that these states that I'm joining are symmetric (will also do this to the 3 and 1 nodes), and then I'm switching the edges from being between the original nodes to go between the new partitions. Finally I'm collapsing the partitions into single nodes.


node, that makes things more complicated. – Torbjørn T. Oct 25 '15 at 15:43coordinatesat certainposon a path and use them to draw connections beween them. – Ignasi Oct 25 '15 at 17:21