【发布时间】:2019-08-22 12:46:07
【问题描述】:
我想创建一个包含多个组 (~10) 的灰度线图,但有一条线 (spec=3) 是红色的。
请看下面只有 3 个组的示例:
year <-c (2011, 2012, 2013, 2011, 2012, 2013, 2011, 2012, 2013)
x <- 1:10
cost <- sample(x, 9, replace=T)
spec <- as.factor(c(1, 1, 1, 2, 2, 2, 3, 3, 3))
dat <-data.frame(year=year, cost=cost, spec=spec)
# graph
library(ggplot2)
ggplot(data=dat, aes(x=year, y=cost, group=spec)) +
geom_line(aes(color=spec)) +
**geom_line(group="3", col="red")** +
scale_colour_grey() +
theme_bw()
问题显然出在geom_line(group="3", col="red") 部分,但我不知道如何解决。
【问题讨论】: