如何在R中翻转堆叠的条形图()?

时间:2017-03-29 04:34:30

标签: r bar-chart

我有一个堆叠的条形图,看起来像vertical stacked barplot

我想翻转这个条形图,看起来像这样:horizontal stacked barplot

我尝试将horiz=FALSE设置为TRUE,但它只是给了我 enter image description here

我的代码是:

mydata <- data.frame(
  row.names =c(100),
  Male =c(50),
  Female =c(50))

x <- 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))

0 个答案:

没有答案