[R] How to label percentage values inside stacked bar plot using R-base

Jim Lemon jim at bitwrit.com.au
Mon Feb 18 11:51:24 CET 2013

On 02/18/2013 06:05 PM, nay-nancy Laiser wrote:
> Hello, I am new to R. I would like others to explain to me how to add
> absolute values inside the individual stacked bars in a consistent way
> using the basic R plotting function (R base). I tried to plot a stacked bar
> graph using R base but the values appear in an inconsistent/illogical way
> in such a way that its supposed to be 100% for each village but they don't
> sum up to 100%.
> Here is the data that am working on:
> Village      100        200         300    400        500
> Male    68.33333    53.33333    70    70       61.66667
> Female  31.66667   46.66667    30   30        38.33333
> In summary, there are five villages and the data showing the head of
> household interviewed by sex.
> I have used the following command towards plotting the graph:
> barplot(mydata,col=c("yellow","green")
> x<-barplot(mydata,col=c("yellow","green")
> text(x,mydata,labels=mydata,pos=3,offset=.5)
> Please help to allocate the correct values in each bar
> Thanks
> Nay
Hi Nay,
You can label the plot you have done above like this:


However, the plot is pretty redundant and you might want to consider 
other ways of presenting the data.


More information about the R-help mailing list