【发布时间】:2018-11-22 09:16:16
【问题描述】:
我想:
- 删除 geom_polygon 图例键和 内的行
- 删除 geom_line 图例键周围的边框。
想要的输出是
到目前为止,我的尝试失败了。提前感谢您的帮助!
library(ggplot2)
set.seed(1337)
dat <- structure(list(id = structure(c(2L, 2L, 2L, 2L),
.Label = c("1.1", "1.2", "1.3", "2.1", "2.2", "2.3"),
class = "factor"),
value = c(3.1, 3.1, 3.1, 3.1),
x = c(2.2, 1.1, 1.2, 2.5),
y = c(0.5, 1, 2.1, 1.7)),
class = "data.frame",
row.names = c(NA, -4L))
line <- data.frame(
x = cumsum(runif(50, max = 0.1)),
y = cumsum(runif(50, max = 0.1))
)
ggplot(dat, aes(x = x, y = y)) +
geom_polygon(aes(color = "Border", group = id), fill = NA) +
geom_line(data = line, aes(colour = "Line"), size = 1) +
theme(legend.background = element_rect(fill = "transparent"),
legend.box.background = element_rect(fill = "transparent", colour = NA),
legend.key = element_rect(fill = "transparent"))
【问题讨论】:
-
想法:在 geoms 中定义您的美学并使用
scale_fill作为颜色。 -
@Masoud:你能把它作为答案发布吗?谢谢
-
这是我之前使用过的解决方法;让我看看我能为你做些什么。