我有一个facet_grid
情节,每情节 2geom_hline
秒。我想分别给每条线上色。我想如果我将这种颜色添加到geom_hline
数据框中,我可以在aes
. 这按组着色,但使用默认的 ggplot 颜色。
这是代码:
p <- qplot(mpg, factor(sample(c("a", "b", "c", "d"), nrow(mtcars), T)),
data=mtcars, facets = vs ~ am)
hline.data <- data.frame(z = factor(c("a", "b", "c", "d")),
vs = c(0,0,1,1), am = c(0,1,0,1))
hline.data <- transform(hline.data, z0 = as.numeric(z))
hline.data <- rbind.data.frame(hline.data, hline.data)
hline.data[5:8, 1] <- c("b", "c", "d", "a")
hline.data[5:8, 4] <- c(2, 3, 4, 1)
hline.data[, "col"] <- rep(c("red", "black"), each=4)
p + geom_hline(aes(yintercept = z0, colour=col), hline.data)
我怎样才能得到geom_hlines
我期待的“红色”和黑色?