<div dir="ltr"><div><p style="margin:0px 0px 1.2em!important">Oscar, I did as you suggested by putting “” for labels that I didn’t want. However, the labels still overlap the drawing :( Here is my code:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span style="color:rgb(51,51,51);font-weight:bold">library</span>(dplyr)
<span style="color:rgb(51,51,51);font-weight:bold">library</span>(maptools)
<span style="color:rgb(153,153,136);font-style:italic">#Known Size of Sheet</span>
xmin <- -<span style="color:rgb(0,128,128)">357.7</span>
xmax <- <span style="color:rgb(0,128,128)">19.3</span>
ymin <- -<span style="color:rgb(0,128,128)">90.2</span>
ymax <- <span style="color:rgb(0,128,128)">159.7</span>
<span style="color:rgb(153,153,136);font-style:italic">#Read in the data</span>
linescoords <- read.csv(<span style="color:rgb(221,17,68)">"Linecoords.csv"</span>)
<span style="color:rgb(153,153,136);font-style:italic">#Coordinates translation</span>
linescoords$X <- linescoords$X - xmin
linescoords$Y <- linescoords$Y - ymin
<span style="color:rgb(153,153,136);font-style:italic"># Plot the figure</span>
xlimit <- c(-<span style="color:rgb(0,128,128)">10</span>, abs(xmin-xmax)+<span style="color:rgb(0,128,128)">10</span> )
ylimit <- c(-<span style="color:rgb(0,128,128)">10</span>, abs(ymin-ymax)+<span style="color:rgb(0,128,128)">10</span> )
plot(linescoords$X, linescoords$Y, <span style="color:rgb(221,17,68)">"p"</span>, xlim=xlimit, ylim = ylimit)
i <- seq(<span style="color:rgb(0,128,128)">1</span>, nrow(linescoords), <span style="color:rgb(0,128,128)">2</span>)
<span style="color:rgb(51,51,51);font-weight:bold">for</span>(x <span style="color:rgb(51,51,51);font-weight:bold">in</span> i){
segments(linescoords$X[x], linescoords$Y[x],
linescoords$X[x+<span style="color:rgb(0,128,128)">1</span>], linescoords$Y[x+<span style="color:rgb(0,128,128)">1</span>])
}
<span style="color:rgb(153,153,136);font-style:italic">#Read in text labels data</span>
labels <- read.csv(<span style="color:rgb(221,17,68)">"labels.csv"</span>)
<span style="color:rgb(153,153,136);font-style:italic">#Text labels Coordinates translation</span>
labels$x <- labels$x - xmin
labels$y <- labels$y - ymin
labels$xminl <- labels$xminl - xmin
labels$xmaxl <- labels$xmaxl - xmin
labels$yminl <- labels$yminl - ymin
labels$ymaxl <- labels$ymaxl - ymin
<span style="color:rgb(153,153,136);font-style:italic">#Point of Origin for labels</span>
points(labels$x, labels$y, pch=<span style="color:rgb(0,128,128)">16</span>, col=<span style="color:rgb(221,17,68)">"red"</span>)
<span style="color:rgb(153,153,136);font-style:italic">#Width & Height of labels</span>
labels <- labels %>% mutate(width=abs(xminl-xmaxl), height=abs(yminl-ymaxl))
oddseq <- seq(<span style="color:rgb(0,128,128)">1</span>, nrow(linescoords),<span style="color:rgb(0,128,128)">2</span>)
evenseq <- seq(<span style="color:rgb(0,128,128)">2</span>, nrow(linescoords),<span style="color:rgb(0,128,128)">2</span>)
x1 <- linescoords$X[oddseq]
y1 <- linescoords$Y[oddseq]
x2 <- linescoords$X[evenseq]
y2 <- linescoords$Y[evenseq]
lineseg <- seq(<span style="color:rgb(0,128,128)">1</span>,length(x1))
lineslope <- as.data.frame(cbind(lineseg, x1, y1, x2, y2))
lineslope <- mutate(lineslope, slope=(y2-y1)/(x2-x1))
pointsx <- vector(<span style="color:rgb(221,17,68)">"list"</span>)
pointsy <- vector(<span style="color:rgb(221,17,68)">"list"</span>)
<span style="color:rgb(51,51,51);font-weight:bold">for</span> (s <span style="color:rgb(51,51,51);font-weight:bold">in</span> <span style="color:rgb(0,128,128)">1</span>:nrow(lineslope)){
<span style="color:rgb(51,51,51);font-weight:bold">if</span>(lineslope[s,<span style="color:rgb(0,128,128)">2</span>]==lineslope[s,<span style="color:rgb(0,128,128)">4</span>]){
louty <- abs(lineslope[s,<span style="color:rgb(0,128,128)">3</span>]-lineslope[s,<span style="color:rgb(0,128,128)">5</span>])/<span style="color:rgb(0,128,128)">3</span>
yp <- seq(lineslope[s,<span style="color:rgb(0,128,128)">3</span>], lineslope[s,<span style="color:rgb(0,128,128)">5</span>], length.out=louty)
pointsy[[s]] <- yp
xp <- seq(lineslope[s,<span style="color:rgb(0,128,128)">2</span>], lineslope[s,<span style="color:rgb(0,128,128)">4</span>], length.out=louty)
pointsx[[s]] <- xp
}
<span style="color:rgb(51,51,51);font-weight:bold">else</span>{
loutx <- abs(lineslope[s,<span style="color:rgb(0,128,128)">2</span>]-lineslope[s,<span style="color:rgb(0,128,128)">4</span>])/<span style="color:rgb(0,128,128)">3</span>
xp <- seq(lineslope[s,<span style="color:rgb(0,128,128)">2</span>], lineslope[s,<span style="color:rgb(0,128,128)">4</span>], length.out=loutx)
pointsx[[s]] <- xp
yp <- seq(lineslope[s,<span style="color:rgb(0,128,128)">3</span>], lineslope[s,<span style="color:rgb(0,128,128)">5</span>], length.out=loutx)
pointsy[[s]] <- yp
}
}
finalx <- unlist(pointsx)
finaly <- unlist(pointsy)
extralabels <- vector(<span style="color:rgb(221,17,68)">"character"</span>, length=length(finalx))
labelsfinal <- append(as.character(labels$Point), extralabels)
X <- append(labels$x, finalx)
Y <- append(labels$y, finaly)
plot(finalx, finaly, <span style="color:rgb(221,17,68)">"p"</span>)
pointLabel(X, Y, labelsfinal)
points(labels$x, labels$y, pch=<span style="color:rgb(0,128,128)">16</span>, col=<span style="color:rgb(221,17,68)">"red"</span>)
</code></pre>
<div title="MDH:T3NjYXIsIEkgZGlkIGFzIHlvdSBzdWdnZXN0ZWQgYnkgcHV0dGluZyAiIiBmb3IgbGFiZWxzIHRo
YXQgSSBkaWRuJ3Qgd2FudC4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gbGluZXNsb3BlW3MsNV0sIGxlbmd0
aC5vdXQ9bG91dHgpPC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7IHBvaW50c3lbW3NdXSAmbHQ7LSB5
cDwvZGl2PjxkaXY+Jm5ic3A7IH08L2Rpdj48ZGl2Pn08L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2
PmZpbmFseCAmbHQ7LSB1bmxpc3QocG9pbnRzeCkmbmJzcDs8L2Rpdj48ZGl2PmZpbmFseSAmbHQ7
LSB1bmxpc3QocG9pbnRzeSk8L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2
PmV4dHJhbGFiZWxzICZsdDstIHZlY3RvcigiY2hhcmFjdGVyIiwgbGVuZ3RoPWxlbmd0aChmaW5h
bHgpKTwvZGl2PjxkaXY+bGFiZWxzZmluYWwgJmx0Oy0gYXBwZW5kKGFzLmNoYXJhY3RlcihsYWJl
bHMkPHdicj5Qb2ludCksIGV4dHJhbGFiZWxzKTwvZGl2PjxkaXY+WCAmbHQ7LSBhcHBlbmQobGFi
ZWxzJHgsIGZpbmFseCk8L2Rpdj48ZGl2PlkgJmx0Oy0gYXBwZW5kKGxhYmVscyR5LCBmaW5hbHkp
PC9kaXY+PGRpdj5wbG90KGZpbmFseCwgZmluYWx5LCAicCIpPC9kaXY+PGRpdj5wb2ludExhYmVs
KFgsIFksIGxhYmVsc2ZpbmFsKTwvZGl2PjxkaXY+cG9pbnRzKGxhYmVscyR4LCBsYWJlbHMkeSwg
cGNoPTE2LCBjb2w9InJlZCIpPC9kaXY+PC9kaXY+PGRpdj5gYGA8L2Rpdj4=" style="min-height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0"></div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Regards<div><br></div><div>Dhiraj Khanna<br></div><div>Mob:09873263331</div></div></div></div></div></div>
<br><div class="gmail_quote">On Sun, Sep 27, 2015 at 9:58 PM, Oscar Perpiñán Lamigueiro <span dir="ltr"><<a href="mailto:oscar.perpinan@upm.es" target="_blank">oscar.perpinan@upm.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> Will using the lineLabel function align the labels as per the<br>
> orientation of the line?<br>
<br>
</span>Yes, exactly.<br>
<span class=""><br>
> Also, I changed the lines to points and then tried the pointLabel<br>
> function. However, it ignores all the points that are not mentioned<br>
> in the argument of the function and still plots over them. Any<br>
> workaround for this?<br>
<br>
</span>You may include empty characters ("") as elements in the _labels_<br>
vector. For example:<br>
<br>
x <- 1:5<br>
y <- 1:5<br>
labels <- c('A', 'B', '', 'D', '')<br>
plot(x, y)<br>
pointLabel(x, y, labels)<br>
<div class="HOEnZb"><div class="h5"><br>
Best.<br>
<br>
Oscar.<br>
<br>
--<br>
Oscar Perpiñán Lamigueiro<br>
Dpto. Ing. Eléctrica, Electrónica, Automática y Física Aplicada<br>
Escuela Técnica Superior de Ingeniería y Diseño Industrial<br>
URL: <a href="http://oscarperpinan.github.io" rel="noreferrer" target="_blank">http://oscarperpinan.github.io</a><br>
</div></div></blockquote></div><br></div>