title: How to flip a stacked barplot() in R?
body: <p>I have a stacked barplot that looks like this <a href="https://i.stack.imgur.com/8Hjph.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Hjph.png" alt="vertical stacked barplot"></a></p>
  
  <p>I want to flip this barplot so that it looks like this: <a href="https://i.stack.imgur.com/75w0E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/75w0E.png" alt="horizontal stacked barplot"></a></p>
  
  <p>I've tried setting <code>horiz=FALSE</code> to TRUE but it just gives me 
  <a href="https://i.stack.imgur.com/LB7LO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LB7LO.png" alt="enter image description here"></a></p>
  
  <p>My code is:</p>
  
  <pre><code>mydata &lt;- data.frame(
    row.names =c(100),
    Male =c(50),
    Female =c(50))
  
  x &lt;- barplot(t(as.matrix(mydata)), horiz=TRUE, axes=FALSE, col=c("yellow", "green"), 
               legend=TRUE, border=NA, xlim=c(0,8), args.legend=
                 list(bty="n", border=NA), 
               ylab="Cumulative percentage", xlab="Village number")
  text(x, mydata$Male-10, labels=round(mydata$Male), col="black")
  text(x, mydata$Male+10, labels=100-round(mydata$Male))
  </code></pre>