Rather than passing a col=
parameter to barchart
, lattice much prefers if you change the par.settings
. In this case. the color of the bars is determined by superpose.polygon because you have different groups of ratings. This should do what you want
data<-data.frame(
service = c("renew_patent", "apply_benefit", "apply_employment_tribunal"),
rating_1 = c(0, 21, 0),
rating_2 = c(0, 20, 0),
rating_3 = c(1, 121, 0),
rating_4 = c(2, 828, 0),
rating_5 = c(11, 1744, 0)
)
colors = c('red', 'orange', 'yellow', 'blue', 'green')
barchart(rating_1+rating_2+rating_3+rating_4+rating_5 ~ service, data=data,
auto.key=list(space='right'), scales=list(x=list(rot=45)),
ylab="Percentage of total", par.settings=list(superpose.polygon=list(col=colors)))