I have a melted data set which also includes data generated from normal distribution. I want to plot empirical density function of my data against normal distribution but the sc
Is this what you had in mind?
There's a built-in variable, ..scaled..
that does this automatically.
set.seed(1)
df<-data.frame(type=rep(c('A','B'),each=100),x=rnorm(200,1,2)/10,y=rnorm(200))
df.m<-melt(df)
ggplot(df.m) +
stat_density(aes(x=value, y=..scaled..,color=variable), position="dodge", geom="line")