Multiple histograms in ggplot2

前端 未结 2 1914
走了就别回头了
走了就别回头了 2020-12-06 02:14

Here is a short part of my data:

dat <-structure(list(sex = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),          


        
2条回答
  •  眼角桃花
    2020-12-06 02:38

    To follow up on chl's example - here's how to duplicate your base graphic with ggplot. I would heed his advice in looking to dotplots as well:

    library(ggplot2)
    dat.m <- melt(dat, "sex") 
    
    ggplot(dat.m, aes(value)) + 
      geom_bar(binwidth = 0.5) + 
      facet_grid(variable ~ sex)
    

提交回复
热议问题