x <- seq(0, 50, 1)
y1 <- exp(0.0509*x)
y2 <- exp(0.0519*x)
df <- data.frame(x,y1,y2)
ggplot(df, aes(x)) +
geom_line(aes(y=y1), colour="blue") +
geom_line(aes(y=y2), colour="red")
根据代码,我想如何为y1添加名为“group 1”的图例,为y2添加“group 2”。 我已经尝试过很多我在这个论坛上看过的东西,但我总是收到错误。
答案 0 :(得分:1)
使用此:
library(reshape2)
library(ggplot2)
gg <- melt(df,id="x")
ggplot(gg, aes(x=x, y=value, color=variable))+
geom_line()