Stacked histograms like in flow cytometry

前端 未结 5 1221
攒了一身酷
攒了一身酷 2020-12-15 14:45

I\'m trying to use ggplot or base R to produce something like the following:

\"enter

5条回答
  •  抹茶落季
    2020-12-15 15:14

    Complementing Axeman's answer, you can add the option stat="binline" to the geom_density_ridges geom. This results in a histogram like plot, instead of a density line.

    library(ggplot2)
    library(ggridges)
    
    my.data <- as.data.frame(rbind( cbind( rnorm(1e3), 1) , 
                                    cbind( rnorm(1e3)+2, 2), 
                                    cbind( rnorm(1e3)+3, 3), 
                                    cbind( rnorm(1e3)+4, 4)))
    my.data$V2 <- as.factor(my.data$V2)
    ggplot(my.data, aes(x=V1, y=factor(V2),  fill=factor(V2))) +
          geom_density_ridges(alpha=0.6, stat="binline", bins=30)
    

    Resulting image: resulting image (as i cannot yet post images here)

提交回复
热议问题