如何为R中的因子绘制一个漂亮的Lorenz曲线(ggplot?)

ale*_*lex 2 plot r distribution ggplot2

我需要一个关于不同因素的不同分布的论文.只有标准的方法似乎package(ineq)足够灵活.

但是,它不允许我在课堂上放点(见下面的评论).重要的是要看到它们,理想情况是单独命名它们.这可能吗?

Distr1 <- c( A=137, B=499, C=311, D=173, E=219, F=81)
Distr2 <- c( G=123, H=400, I=250, J=16)
Distr3 <- c( K=145, L=600, M=120)

library(ineq)
Distr1 <- Lc(Distr1, n = rep(1,length(Distr1)), plot =F)
Distr2 <- Lc(Distr2, n = rep(1,length(Distr2)), plot =F)
Distr3 <- Lc(Distr3, n = rep(1,length(Distr3)), plot =F)

plot(Distr1,
     col="black",
     #type="b",      # !is not working
     lty=1,
     lwd=3,
     main="Lorenz Curve for My Distributions"     
     )

lines(Distr2, lty=2, lwd=3)
lines(Distr3, lty=3, lwd=3)

legend("topleft",
       c("Distr1", "Distr2", "Distr3"),
       lty=c(1,2,3),
       lwd=3)
Run Code Online (Sandbox Code Playgroud)

这就是它现在的样子 在此输入图像描述

raf*_*ira 8

如果您真的想使用ggplot,这是一个简单的解决方案

# Compute the Lorenz curve Lc{ineq}
  library(ineq)
  Distr1 <- c( A=100, B=900, C=230, D=160, E=190, F=40, G=5,H=30,J=60, K=500)
  Distr1 <- Lc(Distr1, n = rep(1,length(Distr1)), plot =F)

# create data.frame from LC
  p <- Distr1[1]
  L <- Distr1[2]
  Distr1_df <- data.frame(p,L)


# plot
  ggplot(data=Distr1_df) +
    geom_point(aes(x=p, y=L)) +
    geom_line(aes(x=p, y=L), color="#990000") +
    scale_x_continuous(name="Cumulative share of X", limits=c(0,1)) + 
    scale_y_continuous(name="Cumulative share of Y", limits=c(0,1)) +
    geom_abline()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述