我在下面有2个分段的情节。
如何为线段添加图例?
理想情况下,最终结果将包含2个图例:
以下是代码
set.seed(11)
x = rnorm(100)
y = rnorm(100)
dat = data.frame(x = x, y = y)
ggplot(dat,aes(x=x,y=y)) + geom_point(aes(color="blue") ) +
geom_segment(aes(x = -2, xend = 2, y = 0, yend = 2), color="red", linetype="dashed", size=1.2) +
geom_segment(aes(x = -1, xend = 1, y = -2, yend = -1), color="red", linetype="dashed", size=1.2) +
scale_color_manual(name = "",values = c("blue"),labels="point legend")