A user wants to add text in the plot but it did not work out.How to fix that?

944    Asked by NaveenYadav in Data Science , Asked on Nov 5, 2019
Answered by Nitin Solanki

Below is the implementation

POPULATION = c(0,7009,14019,21028,28037,35047,42056,49065,56074,63084,70093)

INCOME = c(0,0,0,0,0,195680.26,550667.039999996,1034464.62,1821489.83,3360160.17999999,18979682.83)

DF=data.frame(POPULATION,INCOME)

library(ineq)

G = round(ineq(DF$INCOME,type="Gini"),3)

plot(Lc(DF$INCOME),col="darkred",lwd=2,main="Lorenz Curve", xlab="POPULATION", ylab="INCOME")

The issue might be with the adjustment in text() for justification in the text.

Below code can fix the issue

library(ineq)

POPULATION = c(0,7009,14019,21028,28037,35047,42056,49065,56074,63084,70093)

INCOME = c(0,0,0,0,0,195680.26,550667.039999996,1034464.62,1821489.83,3360160.17999999,18979682.83)

DF=data.frame(POPULATION,INCOME)

G = round(ineq(DF$INCOME,type="Gini"),3)

plot(Lc(DF$INCOME),col="darkred",lwd=2,main="Lorenz Curve", xlab="POPULATION", ylab="INCOME")

text(x=1.0,y=0

     ,labels=paste('Gini = ',G,sep='')

     ,adj = c(1.1,-0.1))

We can also add a legend to the coefficient by adding this to the code.

legend("bottomright", title="GINI",c("0.816"), fill="darkred", cex=0.8)



Your Answer

Interviews

Parent Categories