[R] "helper" lines in plot. From point to axis.
Uwe Ligges
ligges at statistik.tu-dortmund.de
Sun Aug 23 19:57:44 CEST 2009
Looks like nobody answered so far?
If I understood it correctly, you want something like:
x <- 1:36
plot(x, log(x, 1.1), xlab="Number of months", ylab="Visits(1000)",
main="webpage visits")
helper.lines <- function(x, y, lty=2, col="red", text=TRUE){
segments(par("usr")[1], y, x, y, col=col, lty=lty)
mtext(paste("(", round(x), ", ", round(y), ")", sep=""), side=2,
at=y, las=2, outer=FALSE, col=col)
}
helper.lines(x=c(12, 24, 36), y=log(c(12, 24, 36), 1.1), lty=2,
col="red", text=TRUE)
Best,
Uwe Ligges
Andreas Christoffersen wrote:
> This is a very basic question. I am just wondering if there is a function
> where i can choose a vector of points, and them helper lines are drawn.
>
> I am asking because lines seams to be a cumbersome way to do this.
>
> E.g.
> x <- 1:36
> plot(log(x,1.1),xlab="Number of months", ylab="Visits(1000)",main="webpage
> visits")
> abline(h=log(12,1.1),col="red",lty=2)
> mtext(round(log(12,1.1)),side=2,at=log(12,1.1),las=2,outer=F, col="red")
> abline(h=log(24,1.1),col="red",lty=2)
> mtext(round(log(24,1.1)),side=2,at=log(24,1.1),las=2,outer=F, col="red")
> abline(h=log(36,1.1),col="red",lty=2)
> mtext(round(log(36,1.1)),side=2,at=log(36,1.1),las=2,outer=F, col="red")
>
> In this example ablines are easy - but not good because the extend beynd the
> points.
>
> What I would like is something like
> helper.lines(x=c(12,24,36), lty=2, col="red",text=T)
>
> If "text=True" the lines are annotated with the points corresponding x and y
> value.
>
> Is there something that doed this?
>
> Hope my explanation makes sense.
>
> Sincerely.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list