I try to add labels to bars in a lattice barchart with multiple panels. I end up with way too many labels (every label is in every panel).
Here is my code:
library(lattice)
data(iris)
barchart(seq(1,50) ~ Petal.Width + Petal.Length | Species, data = iris, stack = TRUE,
panel=function(x, y, ...) {
panel.barchart(x, y, ...);
ltext(x=iris$Petal.Width/2, y=y, labels=iris$Petal.Width, cex = 0.5);
ltext(x=iris$Petal.Width + iris$Petal.Length/2, y=y, labels=iris$Petal.Width, cex = 0.5);
}
)
How would I do this right?
Bonus question:
Beside it does not work as expected, I think my code is not too efficient (especially seq(1,50)
and Petal.Width + Petal.Length
). Is there a better way?
Thank you in advance!!!