我有2行情节。每一行都有自己的颜色和类型,但是我没有尝试为此绘图创建图例。我创建了2 scale_..._manual
,一个用于线型,另一个用于颜色,但是后者2分隔了传说。如何使用线型和颜色获得单个图例?
library(ggplot2)
x <- c(0,1,2,3,4,5)
y1 <- c(0,2,4,8,16,23)
y2 <- c(0,3,6,9,12,15)
DF <- data.frame(x,y1,y2)
ggplot(data = DF, aes(x = x, y = y1)) +
geom_line(aes(linetype = "First", colour = "First")) +
geom_line(aes(x = x, y = y2, linetype = "Second", colour = "Second")) +
scale_linetype_manual(values = c("First" = 2, "Second" = 1)) +
scale_colour_manual(values = c("First" = "red", "Second" = "blue"))