You should first summarise your dataframe with the plyr
package and then create a barplot:
require(plyr)
require(ggplot2)
# summarise your dataframe into a new one
d2 <- ddply(d, .(place), summarise,
tot = sum(total),
err = sum(error),
val = sum(value))
# create the plot
ggplot(data = d2, aes(x = place, y = val/tot)) +
geom_bar(stat='identity') +
theme(axis.text.x = element_text(angle = 90, hjust = 0.5))
As an alternative you can do it like this:
# create a new variable first
d2$ratio <- d2$val / d2$tot
# create the plot
ggplot(data = d2, aes(x = place, y = ratio)) +
geom_bar(stat='identity') +
theme(axis.text.x = element_text(angle = 90, hjust = 0.5))
The result from the first approach (looks the same for both plotting solutions):