我意识到那里有许多类似标题的查询,但我查看了很多,似乎没有解决我的特定问题。但是,在这方面很高兴出错。
这是一些代码及其制作的情节:
Element not visible: ${element.locator()}
这是一个好的情节,但我需要改变一些事情:
这是我梦想的传奇专栏的MS绘画渲染:
一些注意事项:
library(ggplot2)
set.seed(12345)
types <- c("a", "b")[sample(rep(1:2, each = 5))]
Data <- data.frame(x = rnorm(10),
y = rnorm(10),
Type = types)
p1 <- ggplot(Data, aes(x = x, y = y)) +
geom_point(aes(colour = Type), size = 2.5) +
geom_abline(aes(slope = 0, intercept = 1, colour = "A cool line"), lty = "dotted", lwd = 1.5) +
geom_line(aes(colour = Type), lwd = 1.5) +
ggtitle("abline legend plz")
和lwd
等其他内容,因为我需要处理我正在做的事情。我的解决方案需要允许手动和单独设置。答案 0 :(得分:3)
如果您的水平虚线始终是水平的,我会使用:
p1 <- ggplot(Data, aes(x = x, y = y)) +
geom_point(aes(colour = Type), size = 2.5) +
geom_line(aes(colour = Type), lwd = 1.5) +
geom_hline(aes(yintercept = 1, linetype = "A cool line"), colour = "darkgreen", lwd = 1.5) +
scale_colour_discrete(name = "Type") +
scale_linetype_manual(name = "A cool (custom) title",
values = c("A cool line" = "dotted")) +
ggtitle("abline legend plz") +
guides(colour = guide_legend(override.aes = list(shape = NA)),
linetype = guide_legend(override.aes = list(linetype = "solid")))
如果您想使用geom_abline()
,因为您的虚线可能有斜率,您可以替换
geom_hline(aes(yintercept = 1, linetype = "A cool line"), colour = "darkgreen", lwd = 1.5) +
部分
geom_abline(aes(slope = 0, intercept = 1, linetype = "A cool line"), colour = "darkgreen", lwd = 1.5) +
然而,会用斜线替换图例中的深绿色线条。顺便问一下好问题!