I would like to plot two lines on one chart, one with a color gradient and the other a solid color. I can add individual lines and a gradient:
x <- seq(1, 100, 1)
y <- rnorm(100, 50, 15)
z <- rnorm(100, 30, 5)
df <- data.frame(x,y,z)
library(ggplot2)
ggplot(df, aes(x = x, y = y, color = x)) + geom_line() +
scale_color_gradient(low = "blue", high = "red") +
geom_line(data = df, aes(x = x, y = z, color = x))
But changing the color throws an error:
> ggplot(df, aes(x = x, y = y, color = ..y..)) + geom_line() +
+ scale_color_gradient(low = "blue", high = "red") +
+ geom_line(aes(x = x, y = z, color = "yellow"))
Error: Discrete value supplied to continuous scale
I'm hoping to add labels, but that may be to complex for this...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.