Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add labels to lattice barchart

I would like to place the value for each bar in barchart (lattice) at the top of each bar. However, I cannot find any option with which I can achieve this. I can only find options for the axis.

like image 825
Pieter Avatar asked Jan 27 '10 13:01

Pieter


1 Answers

Create a custom panel function, e.g.

library("lattice")
p <- barchart((1:10)^2~1:10, horiz=FALSE, ylim=c(0,120),
              panel=function(...) { 
                args <- list(...)
                panel.text(args$x, args$y, args$y, pos=3, offset=1)
                panel.barchart(...)
              })
print(p)

lattice barchart with labels

like image 176
rcs Avatar answered Oct 03 '22 16:10

rcs