[Tex/LaTex] How to draw a Venn diagram in TikZ

tikz-pgfvenn-diagrams

I'd like to make this Venn diagram using TikZ (or otherwise at your discretion) based on this post
enter image description here

so far I have this, which looks even worse than a powerpoint attempt

\documentclass{article}
\usepackage{tikz}
\begin{document}


 \def\firstcircle{(0,0) circle (1.5cm)}
 \def\secondcircle{(0:2cm) circle (1.5cm)}

  \colorlet{circle edge}{blue!50}
  \colorlet{circle area}{blue!20}

  \tikzset{filled/.style={fill=circle area, draw=circle edge, thick}, outline/.style={draw=circle edge, thick}}

  \setlength{\parskip}{5mm}
\begin{figure}
\centering
% Set A and B

 \begin{tikzpicture}
  \begin{scope}
    \clip \secondcircle;
    \draw[filled, even odd rule] \firstcircle
                                 \secondcircle node {Env.=242};
  \end{scope}
     \draw[outline] \firstcircle node {Pat=9}
               \secondcircle;
   \node[anchor=south] at (current bounding box.north) {$B - A$};


   \draw (-2.5,-2.5) rectangle (4.5,2.5) node [text=black,above] {$\emptyset$};
   \end{tikzpicture}
   \end{figure}

enter image description here

I'd really appreciate a helping hand here as I do know from the posts that I've seen it should be quite straight forward.
Regards,

EDIT:

Is it possible to put the labels of the sets as they are in the picture? The reason for this is that I have half a dozen Venn diagrams and I'm not sure colour coordination is the easiest to see.

Best Answer

I would suggest some modifications: instead of crowding the diagram with information, you can use colors and a legend to display some of the information; in my example code I used a simple tabular to build the legend; also notice that no additional libraries were used

\documentclass{article}
\usepackage{array}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\def\radius{2cm}
\def\mycolorbox#1{\textcolor{#1}{\rule{2ex}{2ex}}}
\colorlet{colori}{blue!70}
\colorlet{colorii}{red!70}

\coordinate (ceni);
\coordinate[xshift=\radius] (cenii);

\draw[fill=colori,fill opacity=0.5] (ceni) circle (\radius);
\draw[fill=colorii,fill opacity=0.5] (cenii) circle (\radius);

\draw  ([xshift=-20pt,yshift=20pt]current bounding box.north west) 
  rectangle ([xshift=20pt,yshift=-20pt]current bounding box.south east);

\node[yshift=10pt] at (current bounding box.north) {Number of total episodes of case};

\node at ([xshift=\radius]current bounding box.east) 
{
\begin{tabular}{@{}lr@{\,=\,}c@{}}
& Total & 431 \\
\mycolorbox{colori!50} & Env. & 189 \\
\mycolorbox{colorii!50} & Pat. & 422 \\
\end{tabular}
};

\node[xshift=-.5\radius] at (ceni) {$9$};
\node[xshift=.5\radius] at (cenii) {$242$};
\node[xshift=.9\radius] at (ceni) {$180$};
\node[xshift=10pt,yshift=10pt] at (current bounding box.south west) {$\emptyset$};
\end{tikzpicture}

\end{document}

enter image description here

After a comment, here's another variant:

\documentclass{article}
\usepackage{array}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\def\radius{2cm}
\def\mycolorbox#1{\textcolor{#1}{\rule{2ex}{2ex}}}
\colorlet{colori}{blue!70}
\colorlet{colorii}{red!70}

% some coordinates for the center of the circles
\coordinate (ceni);
\coordinate[xshift=\radius] (cenii);

% the circles
\draw (ceni) circle (\radius);
\draw (cenii) circle (\radius);

% the rectangle
\draw  ([xshift=-25pt,yshift=25pt]current bounding box.north west) 
  rectangle ([xshift=25pt,yshift=-25pt]current bounding box.south east);

%the labels
\node[xshift=-.5\radius] at (ceni) {$9$};
\node[xshift=.5\radius] at (cenii) {$242$};
\node[xshift=.9\radius] at (ceni) {$180$};
\node[xshift=-30pt,yshift=\radius+10pt] at (ceni) {Pat.${}=180$};
\node[xshift=30pt,yshift=\radius+10pt] at (cenii) {Env.${}=422$};
\node[xshift=10pt,yshift=10pt] at (current bounding box.south west) {$\emptyset$};
\node[yshift=10pt] at (current bounding box.north) {Number of total episodes of case};
\end{tikzpicture}

\end{document}

enter image description here