Consider the following minimal example:
tab = structure(c(187, 189, 205, 167, 273, 275, 295, 231, 385, 575,
409, 363, 899, 707, 751, 667, 2007, 1953, 2101, 2531, 1043, 1023,
1071, 971, 385, 575, 409, 363, 181, 241, 157, 163, 123, 163,
133, 131), .Dim = c(4L, 9L), .Dimnames = list(NULL, c("-4", "-3",
"-2", "-1", "0", "1", "2", "3", "4")))
The matrix tab
contains counts of a 9-Point Likert Scale.
A basic plot is easy to produce:
likert(tab,
auto.key=list(between=0.5, between.columns=1),
main="Attitudes",
BrewerPaletteName="RdBu",as.percent=TRUE, rightAxisLabels=NULL,
rightAxis=NULL, ylab.right="")
And it looks nice. Now, the problems:
- I would like to control the increments of the percentage axis. In some cases, with other counts, it only shows 50%. I want to enforce 10% increments
- I want to add the % count as a label. Most importantly for the 0-category. Like in Excel, where you right click and say "add data labels". There must be something similar.
I also considered ggplot, however, it does not support the diverging plots. Plus labeling is also quite messy, especially for tikz export.
EDIT I have tried using panel.text. However, I still don't get the numbers alined correctly.
#does not work right!
trellis.focus("toplevel")
for(pp in 1:nrow(tab)){
panel.text(0.5, (pp/nrow(tab))*0.84+0.16, tab[pp,5], cex = 1, font = 2)
}
trellis.unfocus()
How can I find the right positions within each bar?