x1 <- sample(c(0,1,2), size=100, replace=TRUE, prob=c(0.125, 0.375, 0.5))

x2 <- sample(c(0,1,2), size=100, replace=TRUE, prob=c(0.125, 0.375, 0.5))

z = x1 + x2

histPercent <- function(x, ...) {
  H <- hist(x, plot = FALSE)
  H$density <- with(H, 100 * density* diff(breaks)[1])
  labs <- paste(round(H$density), "%", sep="")
  plot(H, freq = FALSE, labels = labs, ylim=c(0, 1.08*max(H$density)),...)
}

histPercent(z, col="gray")