R language Access Menu

Density plot

code:
       > ggplot(bwdf, aes(x=age))+ geom_density()

output (graph):

                    

Following is an interesting custom-built function that produces density curve of all variables of the dataframe sent to it: 

code:
> mydensityall = function(ddf){
    ddf = ddf[sapply(ddf, is.numeric)]
    mm = melt(sapply(ddf, rnscaled_vect))
    print(head(mm))
    ggplot(mm)+stat_density(aes(x=value, group=Var2, color=Var2), geom='line', position='identity')
}

> mydensityall(birthwt[c('age','lwt','bwt')])

output (graph): 

               

One can clearly see that distribution of bwt is different from that of age and lwt variables.


    Comments & Feedback