directlabels - lineplot - example - lars

data(prostate,package="ElemStatLearn")
pros <- subset(prostate,select=-train,train==TRUE)
ycol <- which(names(pros)=="lpsa")
x <- as.matrix(pros[-ycol])
y <- pros[[ycol]]
library(lars)
fit <- lars(x,y,type="lasso")
beta <- scale(coef(fit),FALSE,1/fit$normx)
arclength <- rowSums(abs(beta))
library(reshape2)
path <- data.frame(melt(beta),arclength)
names(path)[1:3] <- c("step","variable","standardized.coef")
library(ggplot2)
p <- ggplot(path,aes(arclength,standardized.coef,colour=variable))+
  geom_line(aes(group=variable))+
  ggtitle("LASSO path for prostate cancer data calculated using the LARS")+
  xlim(0,20)
angled.boxes

Draw a box with the label inside, at the point furthest away from the plot border and any other curve.

direct.label(p,"angled.boxes")
  
first.bumpup

Label first points, bumping labels up if they collide.

direct.label(p,"first.bumpup")
  
first.points

Positioning Method for the first of a group of points.

direct.label(p,"first.points")
  
first.polygons

Draw a speech polygon to the first point.

direct.label(p,"first.polygons")
  
first.qp

Label first points from QP solver that ensures labels do not collide.

direct.label(p,"first.qp")
  
lasso.labels

Label points at the zero before the first nonzero y value.

direct.label(p,"lasso.labels")
  
last.bumpup

Label last points, bumping labels up if they collide.

direct.label(p,"last.bumpup")
  
last.points

Positioning Method for the last of a group of points.

direct.label(p,"last.points")
  
last.polygons

Draw a speech polygon to the last point.

direct.label(p,"last.polygons")
  
last.qp

Label last points from QP solver that ensures labels do not collide.

direct.label(p,"last.qp")
  
lines2

Positioning Method for 2 groups of longitudinal data. One curve is on top of the other one (on average), so we label the top one at its maximal point, and the bottom one at its minimal point. Vertical justification is chosen to minimize collisions with the other line. This may not work so well for data with high variability, but then again lineplots may not be the best for these data either.

direct.label(p,"lines2")
  
maxvar.points

Do first or last, whichever has points most spread out.

direct.label(p,"maxvar.points")
  
maxvar.qp

Label first or last points, whichever are more spread out, and use a QP solver to make sure the labels do not collide.

direct.label(p,"maxvar.qp")
  
Please contact Toby Dylan Hocking if you are using directlabels or have ideas to contribute, thanks!
Documentation website generated from source code version 2021.2.24 (git revision bb6db07 Mon, 14 Jun 2021 22:38:45 +0530) using inlinedocs.
validate