Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
865 views
in Technique[技术] by (71.8m points)

plot - Lorenz Curve in R: remove general line (ineq package 02.13)

I've figured out how to draw a nice lorenz curve that is adjusted to frequency of observations. I use the ineq package, version 02.13.

install.packages("ineq")
library(ineq)

foo <- c(3,5,8,2,1,8,2,9)
foo_n <- c(17,23,30,88,22,7,1,3)

Lc.foo <- Lc(foo, n = foo_n) # n adjusts for the frequency of observations
plot(Lc.foo, general = F, col = "darkred") # 'general = F' is supposed to prevent general line from being plotted

The result is the following plot: simple lorenz curve plot

How can I get rid of the line indicating the perfect equity (aka the straight black line connecting 0|0 and 1|1)? It's more or less the opposite of that question.

Documentation says: Set general = F. As seen in the code above, I've done that, but it has no effect.

For other reasons, I had to fiddle around with my RTools installation and now I get a warning each time when I install ineq. Might a disfunctional RTools be the culprit here? Could any of you replicate the case within an out-of-the-box RTools environment?

Concerning alternative packages: I've already tried gglorenz, but there I don't have a simple way of adjusting for the number of observations. Anyway, I'd be grateful for hints towards other packages that allow for this adjustment.

Thx!


edit:

I've found a way omitting this problem. It's not as neat as the solution proposed by Rui below, but it works:

Just insert this piece of code below plot(...:

#add a white abline that covers the general line that you can't control
lines(x = c(0,1), y = c(0,1), lwd=2, col="white")

If desired, you can now plot an abline with color and style of your choice:

# add a dotted grey line that smoothly indicates equity line
lines(x = c(0,1), y = c(0,1), lwd=1, col="grey40", lty = 3)

These lines cover the Lorenz curves around the positions 0|0 and 1|1 though. For me that's no problem as I have several curves in one plot. The 2nd curve then covers up the white and grey lines. If you wanna plot one curve, better go with Rui's approach.

question from:https://stackoverflow.com/questions/65933370/lorenz-curve-in-r-remove-general-line-ineq-package-02-13

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...