[Tex/LaTex] Positioning text at node

pgfplots

This should be a simple question about positioning text with nodes using pgfplots.

To make a skew node line with text I'd use

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat = newest}

\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{axis}[
    title = DPPH,
    xlabel = Applied Magnetic Field (I Guess) / G,
    xmax = 8,
    xmin = -8,
    ymax = 300,
    ymin = -300,
    ytick = \empty,
    xtick pos = left]

    \addplot[black, % Plotting the data
    no marks]
    table[x=xaxis,y=yaxis] {dpph2.dat};

    \node[coordinate,
    pin = {45:g factor = 1.96}
    ] at (0.2,224) {};

\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

for example.

To make a skew node with rotated text, where I can position the text about the node line using above, below, left, right or a combination of those, I'd change the \node part above to

\node[coordinate,
    pin = {[rotate=45]right:g factor = 1.96}
    ] at (-0.3,250) {};

My question: how do I use above, below, right, etc in the first code (without rotating the text as well as the node line)? I tried things like 45right, 45, right, [45]right, but none of my guesses worked and I can't seem to find an example online.

EDIT

Here's what the first bit of code I put above gives me

enter image description here

and here's what I'd like to be able to do (just move where the text is with respect to the node line)

enter image description here
Thanks.

Best Answer

(Ab)using the code from Jake's answer to How can I force TikZ pin angle?, we can define a new style for the pins that uses a label whose anchor we set to label the text, and an empty pin to draw the line. You supply the arguments like [anchor for label]angle:text to make it similar to the default pin usage. Presumably, there is some way to automatically choose the anchor based on the angle, but my TikZ-fu is not strong enough for that :-) Note that the % at the end of the lines are necessary because of how TikZ interprets spaces.

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\tikzset{
    aligned pin/.style args={[#1]#2:#3}{
        pin={[%
            inner sep=0pt,%
            label={[%
                append after command={%
                    node[%
                        inner sep=0pt,%
                        at=(\tikzlastnode.#2),%
                        anchor=#1,%
                    ]{#3}%
                }%
            ]center:{}}%
        ]#2:{}}%
    }
}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    title = DPPH,
    xlabel = Applied Magnetic Field (I Guess) / G,
    xmax = 8,
    xmin = -8,
    ymax = 300,
    ymin = -300,
    ytick = \empty,
    xtick pos = left
    ]

    \node[coordinate,
    aligned pin={[west]45:g factor=1.96},
    ] at (0,0) {};

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here