# directlabels - utility.function - Positioning Method - dl.move

Sometimes there is 1 label that is placed oddly by another Positioning Function. This function can be used to manually place that label in a good spot.

```dl.move <- structure(function # Manually move a direct label
### Sometimes there is 1 label that is placed oddly by another
### Positioning Function. This function can be used to manually place
### that label in a good spot.
(group,
### Group to change.
x,
### Horizontal position of the new label.
y,
### Vertical position of the new label. If missing(y) and !missing(x)
### then we will calculate a new y value using linear interpolation.
...
### Variables to change for the specified group
){
L <- list(...)
pos <- list()
if(!missing(x))pos\$x <- x
if(!missing(y))pos\$y <- y
pf <- function(d,...,axes2native){
native <- axes2native(do.call(data.frame,pos))
## first convert user-specified axes units to cm
for(var in names(pos)){
u <- unit(native[[var]],"native")
L[[var]] <- convertUnit(u,"cm",var,"location",var,"location")
}
v <- d\$groups==group
for(N in names(L))
d[v,N] <- L[[N]]
## maybe generalize this to be symmetric on x and y one day?
if("x" %in% names(L) && (!"y" %in% names(L))){
orig <- attr(d,"orig.data")
orig <- orig[orig\$groups==group,]
## do linear interpolation to find a good y-value
f <- with(orig,approxfun(x,y))
d[v,"y"] <- f(L\$x)
}
d
}
pf
### A Positioning Function that moves a label into a good spot.
},ex=function(){
library(ggplot2)
library(lattice)
scatter <- xyplot(jitter(cty)~jitter(hwy),mpg,groups=class,aspect=1)
dlcompare(list(scatter),
list("extreme.grid",
`+dl.move`=list(extreme.grid,dl.move("suv",15,15))))

p <- qplot(log10(gamma),rate,data=svmtrain,group=data,colour=data,
geom="line",facets=replicate~nu)