I would suggest you use the extra x ticks option for this. You can supply a list of tick positions using extra x ticks={<list>}, and the corresponding labels using extra x tick labels={<list>}. The style of the extra ticks can be specified using every extra x tick/.style={...}. You can use all the options that are available for "normal" ticks, so you can set x tick label as interval to plot the labels between two tick marks, control the length using major tick length and the style of the tick marks using every tick/.style. The style of the labels can be set using xticklabel style.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:30, samples=100,xtick align=outside, enlarge x limits=false, enlarge y limits=upper,
max space between ticks=40,
extra x ticks={0,4,...,30},
extra x tick labels={1,...,7},
every extra x tick/.style={
xtick align=inside,
x tick label as interval=true,
major tick length=5ex,
every tick/.style={
densely dashed,
red,
},
xtick pos=left,
xticklabel style={
red,
anchor=south
}
},
xlabel=Volume / ml,
after end axis/.code={
\node at (rel axis cs:1,0) [anchor=south west, align=left, red] {Sample\\number};
}
]
\addplot [blue, thick] {(abs(x-18)<3)*(1+cos((x-18)*60))};
\end{axis}
\end{tikzpicture}
\end{document}