# create some data
N = 500
df <- data.frame(ID = 1:N,
category1 = sample(c(1,0), N, replace=TRUE, prob=c(0.4,0.6)),
category2 = sample(c(1,0), N, replace=TRUE, prob=c(0.8,0.2)),
category3 = sample(c(1,0), N, replace=TRUE, prob=c(0.5,0.5)),
category4 = sample(c(1,0), N, replace=TRUE, prob=c(0.3,0.7)),
category5 = sample(c(1,0), N, replace=TRUE, prob=c(0.9,0.1)))
# calculate column percentages
df.percent <- colMeans(df[,-1])
# graph barplot
b <- barplot( df.percent,
ylim = c(0,1),
col=rgb(0.2,0.4,0.6,0.6))
# Add text
text(b, df.percent, labels=paste0(round(df.percent, 2),"%"), pos=3)