I have a facet_grid
plot with 2 geom_hline
s per plot. I'd like to color each of those lines separately. I thought if I added this color to the geom_hline
dataframe I could supply the color inside of aes
. This colors by group but uses the default ggplot colors.
Here's the code:
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)
How can I get the "red" and black geom_hlines
I am expecting?
scale_colour_manual(values = c("red","black"))
? :) Remember, this isn't base graphics! – joran