# [pstricks] Placing labels at arbitrary positions

Herbert Voss LaTeX at zedat.fu-berlin.de
Sun Oct 15 22:47:32 CEST 2006


Matthias Kirchner wrote:
> Hi,
>
> I'm currently doing my first experiences with pstricks. So far, I used
> R to generate my graphs. I found, that the psgraph-environment from the
> pstricks-add package is well suited for my problems. Thus, by writing
> my R-generated values into a file and using \readdata, I end up with
> nice plots. I'm now wondering if there is a macro similar to one which
> I was using heavily with R. There, the function is called "text" and
> has the following functionality:
>
> text(x,y,labels,...)
>
> -> It takes a vector of x and y coordinates  and writes the
> corresponding values which are stored in the labels vector at those
> positions, one label at each (x,y)-pair.
>
> Maybe someone can give me a hint? (The labels should be read from a
> file.)

\listfiles
\documentclass[12pt]{minimal}
\usepackage{filecontents}
\begin{filecontents}{label.data}
0 1 0
1 1.5 2.345
2 3 Joe2
6 2.2 Kathy
10 2.34 1000
\end{filecontents}

\usepackage{pstricks}
\pagestyle{empty}
\parindent=0pt

\makeatletter
\def\psLabelPlot#1{\expandafter\psLabelPlot at i#1}
\def\psLabelPlot at i #1{\psLabelPlot at ii#1}
\def\psLabelPlot at ii#1 #2 #3 #4 #5 #6 {%
\psline[linestyle=dashed](#2,0)(#2,#4)%
\rput*(#2,#4){#6}%
\@ifnextchar D{\psLabelPlot at ii}{}%
}
\makeatother
\begin{document}

\begin{psgraph}(0,0)(10,5){\linewidth}{5cm}