title: ggplot: y-axis (breaks) values from stacked proportional bar graph?
body: <p><strong>Problem solves! Thanks to all of you! (solution at bottom of this post)</strong></p>
  
  <p>I like to create a stacked, proportional bar graph with ggplot. My problem are the breaks of the y-axis, which seem to relate to the percentage value of each bar tile, but does not range from 0 to 100 as expected.</p>
  
  <p>Here's my data frame:</p>
  
  <pre><code>   fg grp  prc
  1   1  g1 85.23
  2   2  g1 14.77
  3   1  g2 73.33
  4   2  g2 26.67
  5   1  g3 85.53
  6   2  g3 14.47
  7   1  g4 87.18
  8   2  g4 12.82
  9   1  g5 72.22
  10  2  g5 27.78
  </code></pre>
  
  <p>This is how I call the plot function:</p>
  
  <pre><code>require(ggplot2)
  ggplot(mydat, aes(x=grp, y=prc, fill=fg)) +
    geom_bar(stat="identity", colour="black", show_guide=FALSE) +
    scale_fill_manual(values=c("#235a80", "#80acc8")) +
    labs(title=NULL, x="Cluster-Gruppen", y=NULL) +
    theme(axis.line = element_line(colour="gray"), 
        axis.text = element_text(size=rel(1.3)), 
        axis.title = element_text(face="italic", size=rel(1.4)))
  </code></pre>
  
  <p>And finally, this is my result:</p>
  
  <p><img src="https://i.stack.imgur.com/OdzD2.png" alt="enter image description here"></p>
  
  <p>As you can see, the y-axis-breaks correspond to the percentage values of the prc-variable.</p>
  
  <p>I would like to have an y-axis-range from 0 to 100 instead, with breaks at every 10th position (<code>seq(0,100,by=10)</code>). Do I need to prepare my data in any way? How do I manage to "fix" the y-axis?</p>
  
  <p>Thanks in advance</p>
  
  <p><em>This is the way how I calculate the data and the working solution!</em></p>
  
  <pre><code>clusterDiskriminanz &lt;- function(myData, groups, gcnt) {
    disc &lt;- lda(groups ~ ., data=myData, na.action="na.omit", CV=TRUE)
    ct &lt;- table(groups, disc$class)
    dg &lt;- diag(prop.table(ct, 1))
    # print barplot for correct percentage for each category of groups
  
    newdat &lt;- NULL
    tmpdat &lt;- NULL
    filldat &lt;- NULL
  
    perc &lt;- round(100*dg,2)
    percrest &lt;-  round(100-perc,2)
  
    # looks strange, but for testing purposes
    # I add data this way. Perhaps I also lack
    # a bit of functions which may do this better and faster
    for (i in 1:gcnt) {
      newdat &lt;- rbind(newdat, c(paste("g",i,sep="")))
      newdat &lt;- rbind(newdat, c(paste("g",i,sep="")))
      tmpdat &lt;- rbind(tmpdat, perc[i])
      tmpdat &lt;- rbind(tmpdat, percrest[i])
      filldat &lt;- rbind(filldat, "1")
      filldat &lt;- rbind(filldat, "2")
    }
  
    # create data frame! prc-values are treated as numeric
    # now! need to convert $g to factors though!
    mydat &lt;- data.frame(filldat, newdat, tmpdat)
    names(mydat) &lt;- c("fg", "grp", "prc")
    mydat$fg &lt;- factor(mydat$fg)
  
    # ggplot-stuff comes here...
    require(ggplot2)
    ggplot(mydat, aes(x=grp, y=prc, fill=fg)) +
      geom_bar(stat="identity", colour="black", show_guide=FALSE) +
      scale_fill_manual(values=c("#235a80", "#80acc8")) +
      labs(title=NULL, x="Cluster-Gruppen", y=NULL) +
      geom_hline(yintercept=totalcorrect, linetype=2, colour="white", alpha=0.8) +
      # Achsenbeschriftung etwas größer machen
      theme(axis.line = element_line(colour="gray"), 
            axis.text = element_text(size=rel(1.3)), 
            axis.title = element_text(face="italic", size=rel(1.4))) + 
      scale_y_continuous(breaks = seq(0, 100, 10)) +
      coord_cartesian(ylim=c(0,100))
    }
  </code></pre>