1

I'm working on a scatter plot and I'd like to call out a handfull of the points by coloring them red and having a black pointer to a label for each one.

So far I've tried creating a new node for each special point and using a pin to label it, but the nodes end up behind the rest of the scatterplot and thus unreadable.

I've also tried creating a second plot with just the special points on the same axis and using meta to label the points. This works well, but I don't get the pointer I wanted. I also need to move the labels farther away from the points because they cover up the other points of the original scatterplot.

I think the solution will be to specify separate coordinates for the labels and then draw a line from the label to the point, but I've reached the limit of my current knowledge and I was unable to glean anything useful from the TikZ manual.

\documentclass[11pt]{article}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{pgfplotstable}
\usepackage{endnotes}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{chngpage}
\usepackage{placeins}
\usepackage{pgfplots}
\usepackage{datatool}
\usepackage{pstricks}
\usepackage{pst-bar}
\usepackage{pst-plot}
\usepackage{tikz}
\usepackage{pgfkeys}

\begin{document}
\centering
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
    width=\textwidth,
    ymin=-4.5,
    ymax=0,
    xmin=0,
    xmax=14,
    axis on top,
    y axis line style={opacity=0}, 
    axis x line*=bottom]
    % This is the full scatterplot. There are about 3500 observations
    \addplot+[
        only marks,
        mark size=.5pt,
        blue]
        table[col sep=comma]{data.csv}; 
    % This is the plot of the specific points to call out
    \addplot+[ 
        mark=*,
        only marks,
        mark size=3pt, 
        color=red, 
        text=black,
        point meta=explicit symbolic,
        nodes near coords] 
        table [meta=pin,col sep=comma] {
            x,           y,             pin
            3.341140458, -0.189121941,  A
            1.722218721, -0.118031264,  B
            1.113494187, 0,             C
            1.040540027, -0.041729947,  D
            2.522133448, 0,             E
            3.344916064, -0.165831522,  F
            4.379923788, -0.574557561,  G
            3.581810739, -0.134014897,  H
        };
    \draw[red,thin] (axis cs:0,0) -- (axis cs:14,0);
\end{axis}
\end{tikzpicture}
\footnotesize{\\This is a caption below the chart.}
\end{figure}

\end{document}

closed as unclear what you're asking by Stefan Pinnow, Zarko, Fran, Mico, Werner Feb 28 '17 at 3:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Welcome to TeX.SX! Can you please add a preamble to your code to show what packages you are using and hence make the code a compilable minimal working example. This makes it much easier for people to help you -- and much more likely that they will. – Andrew Sep 21 '16 at 22:38
  • Thanks! Added. I don't think I'm actually using all of those packages in this example, but this is part of a larger document, so I just grabbed everything. – MsTiggy Sep 22 '16 at 14:52
0

Like this?

enter image description here

For above images for each emphasized points I specify node with pin˙option, which mark its point. For nodes I define new style, and change style forpin`s.

\documentclass[border=3mm,preview]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\usepackage{caption}


\begin{document}
    \begin{figure}
    \centering
\begin{tikzpicture}[
every pin/.style = {pin distance=3mm, 
                font=\scriptsize, inner sep=1pt},
  PN/.style args = {#1/#2}{% Pin Node
    circle, draw=none, fill=red, 
    minimum size=3pt, inner sep=0pt,
    pin=#1:#2}      
                    ]                
\begin{axis}[
    width=\textwidth,
    ymin=-4.5,
    ymax=0,
    xmin=0,
    xmax=14,
    axis on top,
    y axis line style={opacity=0},
    axis x line*=bottom,
    clip=false
]
% This is the full scatterplot. table for about 3500 observations is unknown
%    \addplot+[mark size=.5pt,blue]table[col sep=comma]{data.csv}; 
    \path[draw=red,thin] (0,0) -- (14,0);% <-- changed
% Specific points to call out
\node[PN=180/A] at (3.341140458, -0.189121941) {};
\node[PN=60/B] at (1.722218721, -0.118031264) {};
\node[PN=60/C] at (1.113494187, 0) {};
\node[PN=120/D] at (1.040540027, -0.041729947) {};
\node[PN=60/E] at (2.522133448, 0) {};
\node[PN=60/F] at (3.344916064, -0.165831522) {};
\node[PN=60/G] at (4.379923788, -0.574557561) {};
\node[PN=30/H] at (3.581810739, -0.134014897) {};
\end{axis}
\end{tikzpicture}
\caption*{This is a caption below the chart.}
    \end{figure}
\end{document}
  • This is similar to something I'd already tried. The problem is that the nodes end up behind (in the background of) the full scatterplot and I'm not sure how to bring them forward. – MsTiggy Sep 22 '16 at 14:51
  • This is not a case. Nodes are on the front. If you try the similar solution before, please show your code as MWE in question and show the obtained result of your solution and clarify, what is the problem. – Zarko Sep 22 '16 at 19:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.