[R] how to add a legend in a barchart

Deepayan Sarkar deepayan at stat.wisc.edu
Wed Dec 1 16:26:27 CET 2004

On Wednesday 01 December 2004 05:43, ronggui wrote:
> i use
> #pic 1
> library(lattice)
> barchart(V1~V2,data,panel=function(x,y,...){
> panel.barchart(x,y,...)
> panel.abline(v=6.76,col="red")},
> )
> to draw a picture.and i want to add a legend to telling others the
> line vertical is x=6.76.so how should i do? legend does not works.
> thank you .
> i have use help.search("legend") but no result i want.

But have you read help(barchart)? Look for 'legend' and 'key'.

What you want is not exactly standard, but you may be satisfied with 

         key = list(text = list("6.76"), lines = list(col = "red")))

If not, you can create arbitrary legends using grid.


More information about the R-help mailing list