ggplot: showing % instead of counts in charts of categorical variables

ggplot: showing % instead of counts in charts of categorical variables

require(ggplot2)
## Loading required package: ggplot2
require(scales)
## Loading required package: scales
require(knitr)
p <- ggplot(mtcars, aes(x = hp)) +
  geom_bar(aes(y = (..count..)/sum(..count..))
           , binwidth = 25)
p

plot of chunk unnamed-chunk-3

p <- ggplot(mtcars, aes(x = hp)) +
  geom_bar(aes(y = (..count..)/sum(..count..))
           , binwidth = 25
           , fill = 'white'
           , colour = 'black') +
  scale_y_continuous(labels = percent_format())
p

plot of chunk unnamed-chunk-4

p <- ggplot(mtcars, aes(x = as.factor(cyl) 
                        , fill = as.factor(cyl))) +
  geom_bar(aes(y = (..count..)/sum(..count..))
           , colour = 'black') +
  scale_y_continuous(labels = percent_format())
p

plot of chunk unnamed-chunk-5

p <- ggplot(mtcars, aes(x = as.factor(cyl), fill = as.factor(cyl))) +
  geom_bar(aes(y = (..count..)/sum(..count..))
           , colour = 'black') +
  scale_y_continuous(labels = percent_format()) +
  scale_fill_grey() +
  theme_bw()
p

plot of chunk unnamed-chunk-6