File talk:ParetoLorenzSVG.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Code to generate this plot:

[edit]
library(ggplot2)

#Lorenz curve graph:
N = 10000
F.seq = seq(0, 1, length.out = N)

L = function(F, alpha){
  if (is.infinite(alpha)){
    return(F)
  } else{
    return(1 - (1 - F)^(1 - 1 / alpha))
  }
}
alpha.expression = function(alpha){
  return(paste0("expression(alpha = ", alpha, ")"))
}

alpha.vector = c(1, 2, 3, Inf)
plot.data = data.frame(x = F.seq, y = L(F.seq, alpha.vector[1]), alpha = alpha.vector[1])
for (alpha in alpha.vector[-1]){
  temp.data = data.frame(x = F.seq, y = L(F.seq, alpha), alpha = alpha)
  plot.data = rbind(temp.data, plot.data)
}
plot.data$alpha = factor(plot.data$alpha)
plot.data = plot.data[!((plot.data$alpha == 1) & (plot.data$x >= 0.99)),]

point.data = data.frame(x = c(1, 1), y = c(0, 1))

ggplot(plot.data, aes(x, y)) + geom_line(aes(color = alpha)) + theme_bw() +
  xlab("F") + ylab("L(F)") + theme(axis.title.y = element_text(angle = 0)) +
  geom_point(data = point.data, color = "blue", shape = c(1, 16), size = 3) +
  scale_color_manual(values = c("blue", "green", "red", "black"), name = "",
                     labels = c(expression(alpha == 1), expression(alpha == 2), expression(alpha == 3), expression(alpha == infinity))) +
  theme(legend.position = c(0, 1), legend.justification = c(0, 1), legend.background = element_blank())
ggsave("ParetoLorenz.svg", width = 6, height = 4)