[英]How to change the glyph or icon for geom_abline in the legend?
Im following this example Add regression line legend to geom_abline我按照这个例子将回归线图例添加到 geom_abline
Is there a reason the legend line is slanting?传说线倾斜是有原因的吗? Is it possible for the legend to have a straight red and blue line?
传说中的红蓝直线有可能吗?
Try this.尝试这个。 You can choose the glyph for the legend with argument
key_glyph
.您可以使用参数
key_glyph
为图例选择字形。 To get lines choose key_glyph = "path"
in both geom_abline
layers.要获得线条,请在两个
geom_abline
图层中选择key_glyph = "path"
。
set.seed(1234)
X <- rnorm(20,sd=2.5)
y <- -1+0.5*X+rnorm(20, sd=0.4)
library(ggplot2)
ggplot() +
geom_point(mapping = aes(x = X, y = y)) +
geom_abline(aes(intercept = -0.9930872, slope = 0.4866284, colour = "line1"), lwd=1, key_glyph = "path") +
geom_abline(aes(intercept = -1, slope = 0.5, colour = "line2"), lwd=1, key_glyph = "path") +
scale_colour_manual(values=c("line1"="red","line2"="blue"))
Created on 2020-06-14 by the reprex package (v0.3.0)由代表 package (v0.3.0) 于 2020 年 6 月 14 日创建
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.