I would like to plot two lines and then color segments of a single line with different colors. Here is a simple code:
temp <- data.frame(x = c(2, 4, 5, 5, 7, 6, 7, 8, 10, 9), y = c(3, 8, 4, 8, 8, 4, 9, 12, 5, 1), line = c('a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'b'), color = c('c', 'c', 'd', 'd', 'd', 'c', 'c', 'c', 'd', 'd')) ggplot() + geom_line(aes(x, y, linetype = line, color = ???), data = temp) I want to color segments of each line using the color factor. Any help? Thank you in advance!
colorin place of???ggplot(temp, aes(x, y)) + geom_line(aes(linetype = line)) + geom_point(aes(color = color)), we could make the lines between the red points red and the lines between the blue points blue. What color do you want the lines between the red and blue points??