I would like to plot some data as a scatter plot using facet_wrap, overlaying some information such as linear regression and density. I managed to do all this, but the density values ββdo not correspond to my points, which is a normal thing, since these points are far away. However, I would like to scale and move my density curve so that it is clearly visible; I don't care about real values, but more about its form.
Here is an exaggerated minimum working example of what I have:
set.seed(48151623) mydf <- data.frame(x1=rnorm(mean=5,n=100),x2=rnorm(n=100,mean=10),x3=rnorm(n=100,mean=20,sd=3)) mydf$var <- mydf$x1 + mydf$x2 * mydf$x3 mydf.wide <- melt(mydf,id.vars='var',measure.vars=c(1:3)) ggplot(data=mydf.wide,aes(x=value,y=var)) + geom_point(colour='red') + geom_smooth(method='lm') + stat_density(aes(x=value,y=..scaled..),position='identity',geom='line') + facet_wrap(~variable,scale='free_x')
The result is: 
What I would like to be like this ugly hack:
stat_density(aes(x=value,y=..scaled..*100+200),position='identity',geom='line')
Ideally, I would use y=..scaled..* diff(range(value)) + min(value) , but when I do this, I get an error "Value" was not found. I suspect the problem is faceting, but I would rather keep my facets.
How can I scale and move the density curve in this case?
