Imagine I have two vectors each of different length. I want to generate one plot with the density of both vectors overlaid. What I thought I should do is this:
Everything will work fine if you move the assignment of the colour parameter out of aes().
colour
aes()
vec1 <- data.frame(x=rnorm(2000, 0, 1)) vec2 <- data.frame(x=rnorm(3000, 1, 1.5)) library(ggplot2) ggplot() + geom_density(aes(x=x), colour="red", data=vec1) + geom_density(aes(x=x), colour="blue", data=vec2)