I am trying to replicate a plot like this one in latex. I wonder if anyone has some good example codes to share? many thanks,
-
It's more a drawing, less a bar chart. So I suggest to peek into the pgf-manual, e.g. here: tikz.dev/tutorials-guidelines . Th eelements you'll need from it are node[draw,fill=blue] (bar), draw[->] (for the arrows), node[anchor= ...] (labels). For the brace there are several options. // I suggest to try a little and add code, better sooner than later, to your question.– MS-SPOCommented Jul 9 at 15:26
Add a comment
|
1 Answer
Something to get you started; keys:
- absolute positions AND related to the nodes anchors
- you could switch to matrix placement for more flexibility
- place basic elements first
- introduce and modify styles as needed
- choose your favorite color model from LaTeX or TikZ
From a refactoring perspective the \draw
commands qualify for standardization, e.g as a \newcommand
.
\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
trt/.style={anchor=west},
bb/.style={ draw,fill=blue!100!cyan!50,
inner sep=0mm,minimum height=5mm,anchor=west},
>={Stealth},
an/.style={anchor=north},
]
% ~~~ entry ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\node[trt] (T1) at (0,0) {Treated};
% ~~~ "bars" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\node[bb,minimum width=4cm] (B1) at (3,0) {};
\node[bb,minimum width=2cm] (B2) at (B1.east) {};
% ~~~ arrows ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\draw[<-] (B1.south west) -- +(0,-.4) node[an] {Start of follow-up};
\draw[<-] (B1.south east) -- +(0,-.4) node[an] {First prescription};
\end{tikzpicture}
\end{document}
-
1