I have the following code that produces the plot attached. I am wondering how to include a legend in the formation of the graph as I can't seem to be able to do this. The manual legend I want is the "cols" vector, detailing the different colours for each sample size.
N <- 100
gamma <- 1/12 #scale parameter
beta <- 0.6 #shape parameter
u <- runif(N)
v <- runif(N)
tau <- -gamma*log(u)*(sin(beta*pi)/tan(beta*pi*v)-cos(beta*pi))^(1/beta)
OX <- sort(tau)
CumWealth <- cumsum(OX)/sum(tau)
PoorPopulation <- c(1:N)/N
index <- c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.99,0.999,0.9999,0.99999,0.999999,1)*N
QQth <- CumWealth[index]
x <- PoorPopulation[index]
Lorenzdf <- data.frame(x, QQth)
cols <- c("100"="blue","1000"="green","10000"="red", "1e+05" = "black")
colors = c("green", "red", "black")
g <- ggplot(data=Lorenzdf, aes(x=x, y=QQth)) +
geom_point(color = "blue") +
geom_line(color = "blue") +
ggtitle(paste("Convergence of empirical Lorenz curve for Beta = ", beta, sep = " ")) +
xlab("Cumulative share of people from lowest to highest wealth") +
ylab("Cumulative share of wealth") +
scale_color_manual(name="Sample size",values=cols)
sample_sizes <- c(1000, 10000, 100000)
for (i in 1:3) {
gamma <- 1/12 #scale parameter
beta <- 0.6 #shape parameter
u <- runif(sample_sizes[i])
v <- runif(sample_sizes[i])
tau <- -gamma*log(u)*(sin(beta*pi)/tan(beta*pi*v)-cos(beta*pi))^(1/beta)
OX <- sort(tau)
CumWealth <- cumsum(OX)/sum(tau)
PoorPopulation <- c(1:sample_sizes[i])/sample_sizes[i]
index < c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95,0.99,0.999,0.9999,0.99999,0.999999,1)*sample_sizes[i]
QQth <- CumWealth[index]
x <- PoorPopulation[index]
Lorenzdf <- data.frame(x, QQth)
g <- g + geom_point(data = Lorenzdf, aes(x = x, y = QQth), color = colors[i])
g <- g + geom_line(data = Lorenzdf, aes(x = x, y = QQth), color = colors[i])
}
g