0

With a data frame df and a column col_name I generate histograms like below.

ggplot(df, aes_string(x=col_name)) + 
    geom_histogram(aes(y=..density..),
                   binwidth=1,
                   colour="black", fill="white")

This gives me a histogram like below. I need to change two things in this.

  1. display the density values at the top inside each bar
  2. change the density value to percentage - instead of 0.4 , show 40%

histogram

user3206440
  • 4,749
  • 15
  • 75
  • 132
  • 1
    1. http://stackoverflow.com/questions/29869862/ggplot2-how-to-add-percentage-or-count-labels-above-percentage-bar-plot 2. Use `scale_y_continuous(labels=percent)` from the `scales` package. – conrad-mac Jan 29 '17 at 02:06
  • Use stat_bin with geom = 'text'. See: http://stackoverflow.com/questions/24198896/how-to-get-data-labels-for-a-histogram-in-ggplot2 – Peter K Jan 29 '17 at 05:05

0 Answers0