My query is with reference to this reprex:
d1 <- data.frame(index= 1:100,x=1:100,x_hat= 1:100+ rnorm(100))
ggplot(data = d1 ) +
geom_line(aes(x=index,y=x,color="True X")) +
geom_line(aes(x=index,y=x_hat,color="Estimated X")) +
scale_x_continuous(name = "" ) +
ylab("")
The code is doing what I want it to do but I don't know how it is doing it. When I say color = "True X" I think it is generating a variable on the fly which is a constant.
Is that correct ? How is it working ? Can someone say a few words on this ? The beauty of this approach is that it automatically creates a correct legend.