Skip to Content

adding labels on bottom of barchart

I'm quite new to lattice so for me its a trial and error run here.

It seems to customize lattice graphics cannot be done with the typical r-understanding.

I would like to add something like count(percentage) beneath each bar which is supposed to look like this when its done:

As you can see my code does not label the bars right. Not all of them and wrong. The first is supposed to be 20(0.1%).

Here my code:

grp <- c(grp1,grp2,grp3,grp4)
    par.settings = list(
    plot.polygon = list(col = c("#1E4150","#28556E","#32698C","#3C7DAA")) ),
        panel = function(x, y, subscripts, ...){  
            X <- table(x)
            percentages <- paste(round(table(X)/length(X),2),"%",sep="")
            lab1 <- paste( "(",percentages, sep="")
            lab1 <- paste( lab1,")", sep="")
            abs <- table(X)
            panel.text(1,-3, label = paste(abs,lab1), cex=0.8)