[Tex/LaTex] “Collision” between marker labels in pgfplots scatter plot

pgfplots

Sometimes, it's hard to avoid "colliding" marker labels in scatter plots, by which I mean labels that overlap each other. If I don't want to remove data points to avoid the overlap, is it possible to shift individual labels (as with TikZ nodes)? The following MWE illustrates the problem:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture} 
\begin{axis}[
    xlabel=$a$,
    ylabel=$b$
]
\addplot[blue,mark=*,mark options={fill=blue},nodes near coords,only marks,
   point meta=explicit symbolic] table[meta=label] {
x y label
100 152 {Long label 1}
200 180 {Long label 2}
110 150 {Long label 3}
};
\end{axis}
\end{tikzpicture}
\end{document}

Ideally, I would like to be able to adjust selected labels left/right/up/down. Thanks!

Best Answer

You can add your preferred anchor and possibly other properties as follows,

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture} 
\begin{axis}[
    xlabel=$a$,
    ylabel=$b$,
]
\addplot[blue,mark=*,mark options={fill=blue},nodes near coords,only marks,
   point meta=explicit symbolic,
   visualization depends on={value \thisrow{anchor}\as\myanchor},
   every node near coord/.append style={anchor=\myanchor}
] table[meta=label] {
x y label anchor
100 152 {Long label 1} south
200 180 {Long label 2} east
110 150 {Long label 3} west
};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Here, you can actually make it more complicated as testing whether \thisrow{} is empty or not then use the default or the input value etc.