title: Adding text on each bar in horizontal bar plot in ggplot
body: <p>I want to add text (<code>n</code>) on each bar in a horizontal bar plot in <code>ggplot</code> environment, but keep getting error message, I wonder what will be correct way to do so?
  Also, I tried to invoke <code>viridis</code> package to add color on those bars but can't seem to get around. Is there any way to map different colors to those bars?</p>
  <p>My current code is shown at below.</p>
  <pre><code>    # the data
  
      city_r &lt;- data.frame(
      City = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;),
      rating = c(5.52, 8, 6.24, 5.89, 5.57, 8.67),
      n = c(112, 1, 25, 40, 9, 36)
                       )
      # rating means mayor's rating
      # n means respondents' size in each city
  
      library(ggplot2)
  
      # plot it
      g &lt;- city_r %&gt;% 
        group_by(City) %&gt;% 
        arrange(rating) %&gt;% 
        ggplot(., mapping = aes(x=reorder(City, rating), y =rating))+
        geom_text(aes(n), colour = &quot;black&quot;, position = &quot;dodge&quot;) +
        geom_bar(stat = &quot;identity&quot;, width=.8, position = position_dodge(width = .25))+
        labs(
          title = &quot;&quot;,
          y = &quot;Mayor's rating&quot;,
          x = &quot;&quot;
        )+
        coord_flip()
        
       g
        
  
  </code></pre>