X- axis labels are not properly aligned in R barplot

...I have data.table data to create a stacked chart and with grouping using below code:

causesDf <- causesDf[, c('Type', 'Gender', 'Total')]
causesSort <- causesDf[, lapply(.SD, sum), 
                       by=list(causesDf$Type, causesDf$Gender)]

and Data will be like below:

                       causesDf causesDf.1  Total

     1:                        Illness (Aids/STD)                    Female   2892
     2:                 Change in Economic Status            Female   4235
     3:   Cancellation/Non-Settlement of Marriage     Female   6126       
     4:                           Family Problems                    Female 133181
     5:                        Illness (Aids/STD)                     Male   5831
     6:                 Change in Economic Status             Male  31175
     7:    Cancellation/Non-Settlement of Marriage     Male   5170

and so on..

I am trying to make barplot like below:

barpos <- barplot(sort(causesSort$Total, decreasing=TRUE),
                      col=c("red","green"), xlab="", ylab="", 
                      horiz=FALSE, las=2)
    legend("topright", c("Male","Female"), fill=c("red","green"))
    end_point <- 0.2 + nrow(causesSort) + nrow(causesSort) - 0.1
    text(seq(0.1, end_point, by=1), par("usr")[3] - 30,
         srt=60, adj= 1, xpd=TRUE,
         labels=paste(causesSort$causesDf), cex=0.65)

but X-labels are not aligning properly, did I miss anything?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.