Вопрос

I need a nice plot for my thesis on the different distributions of different factors. Only the standard approach seemed with the package(ineq) was flexible enough.

However, it doesn't let me to put dots (see comment below) at the classes. It is important to see them, ideally to name them individually. Is this possible?

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)

This is how it looks now enter image description here

Это было полезно?

Решение 2

To show the problem, only Distr1 is needed; it' good to strip down before posting.

library(ineq)
Distr1 <- c( A=137, B=499, C=311, D=173, E=219, F=81)

Distr1 <- Lc(Distr1, n = rep(1,length(Distr1)), plot =F)
plot(Distr1$p,Distr1$L,
     col="black",
     type="b",      # it should be "b"
     lty=1,
     lwd=3,
     main="Lorenz Curve for My Distributions"     
)

Другие советы

In case you really want to use ggplot, here is a simple solution

# 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()

enter image description here

As there is a package (gglorenz) handling Lorenz Curves automatically for ggplot, I add this:

library(ggplot2)
library(gglorenz)

Distr1 <- c( A=137, B=499, C=311, D=173, E=219, F=81)
x <- data.frame(Distr1)

ggplot(x, aes(Distr1)) + 
  stat_lorenz() + 
  geom_abline(color = "grey")

enter image description here

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top