ggplot2: Overlay density plots R

前端 未结 3 1867
名媛妹妹
名媛妹妹 2020-12-13 04:23

I want to overlay a few density plots in R and know that there are a few ways to do that, but they don\'t work for me for a reason or another (\'sm\' library doesn\'t instal

3条回答
  •  孤城傲影
    2020-12-13 04:35

    Some people have asked if you can do this when the distributions are of different lengths. The answer is yes, just use a list instead of a data frame.

    library(ggplot2)
    library(reshape2)
    x <- list(v1=rnorm(100),v2=rnorm(50,1,1),v3=rnorm(75,0,2))
    data<- melt(x)
    ggplot(data,aes(x=value, fill=L1)) + geom_density(alpha=0.25)
    ggplot(data,aes(x=value, fill=L1)) + geom_histogram(alpha=0.25)
    ggplot(data,aes(x=L1, y=value, fill=L1)) + geom_boxplot()
    

提交回复
热议问题