To get a color gradient on your line, you need:
- split your x-axis onto the smaller pieces (use
by = argument in the seq()). The smaller pieces - the smoother gradient. If you set it to 0.2 you will get 5 steps from green to red.
- Use
aes(color = values) to scale the color
- Use
scale_color_gradient(low = "green", high = "red") to define how colors should change
suppressMessages(library(tidyverse))
slider <- data.frame("values"=seq(0, 1, by = 0.01))
dot_value <- data.frame("Result"= 0.8)
ggplot(slider, aes(x=values, y=0)) +
geom_line(aes(color = values),
size=1.5)+
geom_point(data=dot_value,
mapping = aes(as.numeric(Result)),size=4)+
scale_color_gradient(low = "green", high = "red") +
theme(axis.ticks.y=element_blank(),
axis.text.y=element_blank()) +
xlab("")+
ylab("")
