【发布时间】:2019-09-28 22:52:14
【问题描述】:
我正在尝试为已添加到现有 ggplot 的行添加一个键。
设置:
test.mat <- data.frame(matrix(nrow=32, ncol =3))
test.mat[,1] = rep(1:16,2)
test.mat[1:16,2] = as.character(rep("Cohort Alpha"),16)
test.mat[17:32,2] = as.character(rep("Factor Alpha"), 16)
test.mat[,3] = rnorm(32,0,1)
colnames(test.mat) = c("Window", "type", "value")
ggplot(test.mat, aes(x=Window, y=value, size = type)) +
geom_line(aes(colour = type, linetype = type)) +
scale_colour_manual("type", values = c("black", "steelblue")) +
scale_linetype_manual("type", values = c("solid", "solid")) +
scale_size_manual("type", values = c(0.8, 1.4), guide = "none") +
xlab("Quarter after alpha assessment") + ylab("t-statistics") + ggtitle("Panel Regression t-statistics") + theme_classic() +
theme(
text = element_text(family = "Times New Roman"),
plot.title = element_text(color = "black", size = 12, hjust = 0.5),
axis.title = element_text(size = 12),
legend.title = element_blank()) +
geom_hline(yintercept = 1.282 , color = "dark green") +
geom_hline(yintercept = 1.645 , color = "dark grey") +
geom_hline(yintercept = 2.326 , color = "grey")
我想要标记为“*”的深绿色线,我想要标记为“**”的深灰色线,并且我想要标记为“***”的灰色线。我希望这些标签出现在图例中。
【问题讨论】: