I have a plot with three ECDFs and three vertical lines, and cannot get the stat_ecdf legend line color to match the actual line color.
Here is the code for just the ECDF plot:
set.seed(124)
allDTI <- data.frame(values=rnorm(1000,500,200),type=sample(LETTERS[1:3],1000,T))
meanALLDTI <- ddply(allDTI, "type", summarise, values.mean=mean(values, na.rm=TRUE), n)
ggplot(allDTI, aes(x=values, color=type)) +
stat_ecdf(size=1, show_guide=T) +
xlab(expression('Index Value')) +
ylab("Cumulative Density") +
ggtitle(expression(TI[d]~'and'~TI[l]~'and'~TI[w])) +
scale_x_continuous(expand = c(0,0)) +
scale_y_continuous(expand = c(0,0)) +
theme(text = element_text(size=20),
plot.title = element_text(size=30,face="bold",vjust=1),
axis.title.x=element_text(size=20,face="bold",vjust=0,hjust=0.5),
axis.title.y=element_text(size=20,face="bold",vjust=1.0,hjust=0.5),
legend.position = c(0.85, 0.25),
legend.text.align = 0,
legend.box = 'horizontal',
legend.margin = unit(45.0, 'line'),
legend.text=element_text(size=28,vjust=0,hjust=0),
legend.key.height = unit(1.5, 'line'),
legend.key.width = unit(1.5, 'line'),
panel.background = element_rect(fill = "white")) +
scale_color_manual(values=c('grey10','grey30','grey50'),
labels=c(expression(TI[d]),expression(TI[l]),
expression(TI[w]))) +
guides(color = guide_legend(title=NULL))
Here is the plot:
But I can't figure out how to add the vertical lines I want to add in the manner I want to add them:
Code:
ggplot(allDTI, aes(x=values, color=type)) +
stat_ecdf(size=1, show_guide=T) +
xlab(expression('Index Value')) +
ylab("Cumulative Density") +
ggtitle(expression(TI[d]~'and'~TI[l]~'and'~TI[w])) +
scale_x_continuous(expand = c(0,0)) +
scale_y_continuous(expand = c(0,0)) +
theme(text = element_text(size=20),
plot.title = element_text(size=30,face="bold",vjust=1),
axis.title.x=element_text(size=20,face="bold",vjust=0,hjust=0.5),
axis.title.y=element_text(size=20,face="bold",vjust=1.0,hjust=0.5),
legend.position = c(0.85, 0.25),
legend.text.align = 0,
legend.box = 'horizontal',
legend.margin = unit(45.0, 'line'),
legend.text=element_text(size=28,vjust=0,hjust=0),
legend.key.height = unit(1.5, 'line'),
legend.key.width = unit(1.5, 'line'),
panel.background = element_rect(fill = "white")) +
scale_color_manual(values=c('grey10','grey30','grey50'),
labels=c(expression(TI[d]),expression(TI[l]),
expression(TI[w]))) +
guides(color = guide_legend(title=NULL)) +
geom_vline(data=meanALLDTI, aes(xintercept=values.mean, colour=type),
linetype="dashed", size=1, show_guide=T) +
scale_linetype_manual(values=c('grey10','grey30','grey50'),
labels=c(expression(bar(TI[d])),expression(bar(TI[l])),
expression(bar(TI[w])))) +
guides(linetype= guide_legend(title=NULL))
As an example of what I want, here is how it came out for me with density plots: