# [R-sig-Geo] Help on pointLabel() function for engineering drawings

Dhiraj Khanna dhirajkhanna at gmail.com
Mon Sep 28 14:46:22 CEST 2015

```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:

library(dplyr)library(maptools)#Known Size of Sheet
xmin <- -357.7
xmax <- 19.3
ymin <- -90.2
ymax <- 159.7
#Read in the data
#Coordinates translation
linescoords\$X  <- linescoords\$X - xmin
linescoords\$Y <- linescoords\$Y - ymin
# Plot the figure
xlimit <- c(-10, abs(xmin-xmax)+10 )
ylimit <- c(-10, abs(ymin-ymax)+10 )
plot(linescoords\$X, linescoords\$Y, "p", xlim=xlimit, ylim = ylimit)

i <- seq(1, nrow(linescoords), 2)for(x in i){
segments(linescoords\$X[x], linescoords\$Y[x],
linescoords\$X[x+1], linescoords\$Y[x+1])
}
#Read in text labels data
#Text labels Coordinates translation
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
#Point of Origin for labels
points(labels\$x, labels\$y, pch=16, col="red")
#Width & Height of labels
labels <- labels %>% mutate(width=abs(xminl-xmaxl), height=abs(yminl-ymaxl))

oddseq <- seq(1, nrow(linescoords),2)
evenseq <- seq(2, nrow(linescoords),2)

x1 <- linescoords\$X[oddseq]
y1 <- linescoords\$Y[oddseq]
x2 <- linescoords\$X[evenseq]
y2 <- linescoords\$Y[evenseq]
lineseg <- seq(1,length(x1))

lineslope <- as.data.frame(cbind(lineseg, x1, y1, x2, y2))

lineslope <- mutate(lineslope, slope=(y2-y1)/(x2-x1))

pointsx <- vector("list")
pointsy <- vector("list")for (s in 1:nrow(lineslope)){

if(lineslope[s,2]==lineslope[s,4]){
louty <- abs(lineslope[s,3]-lineslope[s,5])/3
yp <- seq(lineslope[s,3], lineslope[s,5], length.out=louty)
pointsy[[s]] <- yp
xp <- seq(lineslope[s,2], lineslope[s,4], length.out=louty)
pointsx[[s]] <- xp
}
else{
loutx <- abs(lineslope[s,2]-lineslope[s,4])/3
xp <- seq(lineslope[s,2], lineslope[s,4], length.out=loutx)
pointsx[[s]] <- xp
yp <- seq(lineslope[s,3], lineslope[s,5], length.out=loutx)
pointsy[[s]] <- yp
}
}

finalx <- unlist(pointsx)
finaly <- unlist(pointsy)

extralabels <- vector("character", length=length(finalx))
labelsfinal <- append(as.character(labels\$Point), extralabels)
X <- append(labels\$x, finalx)
Y <- append(labels\$y, finaly)
plot(finalx, finaly, "p")
pointLabel(X, Y, labelsfinal)
points(labels\$x, labels\$y, pch=16, col="red")

​

Regards

Dhiraj Khanna
Mob:09873263331

On Sun, Sep 27, 2015 at 9:58 PM, Oscar Perpiñán Lamigueiro <
oscar.perpinan at upm.es> wrote:

> > Will using the lineLabel function align the labels as per the
> > orientation of the line?
>
> Yes, exactly.
>
> > Also, I changed the lines to points and then tried the pointLabel
> > function.  However, it ignores all the points that are not mentioned
> > in the argument of the function and still plots over them. Any
> > workaround for this?
>
> You may include empty characters ("") as elements in the _labels_
> vector. For example:
>
> x <- 1:5
> y <- 1:5
> labels <- c('A', 'B', '', 'D', '')
> plot(x, y)
> pointLabel(x, y, labels)
>
> Best.
>
> Oscar.
>
> --
> Oscar Perpiñán Lamigueiro
> Dpto. Ing. Eléctrica, Electrónica, Automática y Física Aplicada
> Escuela Técnica Superior de Ingeniería y Diseño Industrial
> URL: http://oscarperpinan.github.io
>
-------------- next part --------------
An HTML attachment was scrubbed...