I am not sure if I have understood your question correctly, but is this what you want?
ggplot(data.df)
+geom_density(aes(x=active,y=..scaled..,fill=name),position="stack")
ggplot2
's help under stat_density
says that scaled
gives the "density estimate, scaled to maximum of 1".
Alternatively, you could also add a weight column (e.g., wght
) to your data.frame
, use the weight
argument in geom_density
and ignore the warning message
data.df=data.frame(name=c("type1","type1","type1","type1","type1","type1","type2", "type2","type2"),active=c(1.1,1,1,1,1,1,17.1,17,17),stringsAsFactors =FALSE)
data.df=within(data.df,wght<-c(rep(1/6,6),rep(4/9,3)))
ggplot(data.df)+
geom_density(aes(x=active,y=(..density..),fill=name,weight=wght),position="stack")
However, I do not exactly know how geom_density
handles weights that do not sum up to 1.