[R] Data Labels in a barchart (Lattice or otherwise)

David Winsemius dwinsemius at comcast.net
Tue Jul 6 00:37:46 CEST 2010


On Jul 5, 2010, at 1:14 PM, RaoulD wrote:

>
> Thank You David. Yes, I am using the lattice barchart and have  
> managed to add
> data labels, however, they tend to be on the tip of each bar and are
> difficult to read as they are partially on the bar. Any help would be
> greatly appreciated.
>
> This is the code I am using:
> levels(PR_SUMMARY$Bucket)=c("0-3 months","3-9 months","9-15  
> months","15-18
> months")
> barchart(PrimaryReason ~ cInteractions| Bucket + Type, data =  
> PR_SUMMARY,
> layout = c(4, 2),col="lightgreen",main="COMPARISON - PRIMARY REASON",
>           sub="L & R",xlab="Number of Customers",ylab="Primary  
> Reasons",
>           auto.key = list(title = "COMPARISON - PRIMARY
> REASON",columns=2,points = FALSE, rectangles =          TRUE,space=  
> "right"
> ),scales = list(x = list(abbreviate=TRUE,minlength=5,rot=45)),
>           panel = function(x,y,subscripts,groups,...){
>                panel.barchart(x,y,...)
>                ltext(x,y,label=round(PR_SUMMARY$cInteractions,1),
> cex=.99,rot=45)

# if you add or subtract a small amount from "y" in the prior line it  
will move the labels up or down.

>                border="transparent"})
>
> I dont really understand the "ltext" part and found it with some  
> other code,
> but it works.
>
> Thanks again,
> Raoul
> -- 


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list