这是我最小的工作示例:
library(ggplot2)
library(dplyr)
n = 200
p = 10
df <- data.frame(
x = 1:n/p,
y = 2*sin(1:n/p) + 1:n/p + runif(n)) %>%
mutate(a = rep(sum(y)/length(x), n))
ggplot(df, aes(x = x)) +
geom_line(aes(y = y, fill = "LINE1")) +
geom_line(aes(y = a, fill = "LINE2")) +
geom_abline(aes(fill = "LINE3")) +
theme_classic() +
scale_colour_manual(values = c(
"LINE1" = "red",
"LINE2" = "blue",
"LINE3" = "orange"))
虽然我确实得到了一个情节,但它没有传说。我也没有颜色。我做错了什么?