Functions available for Tufte boxplots in R?

后端 未结 5 766
感动是毒
感动是毒 2020-12-08 05:27

I have some data that I\'ve divided into enough groupings that standard boxplots look very crowded. Tufte has his own boxplots in which you basically drop all or half of bo

5条回答
  •  旧时难觅i
    2020-12-08 05:54

    Here is the customary ggplot solution (or rather a hack with scope for elegance)

    require(ggplot2)
    
    # melt the data frame
    cw2 = melt(cw, id = 'weight')
    
    # create a data frame with boxplot stats
    cw3 = ddply(cw2, .(value, variable), function(df) boxplot.stats(df$weight)$stats)
    
    # generate the plot
    ggplot(cw2, aes(value, weight)) +
      geom_boxplot(fill = 'gray90', colour = 'gray90', alpha = 0) +      
      geom_segment(data = cw3, aes(xend = value, y = V1, yend = V2)) + 
      geom_segment(data = cw3, aes(xend = value, y = V4, yend = V5)) + 
      geom_point(data = cw3, aes(y = V3), size = 3) + 
      facet_wrap(~ variable, scales = 'free_x', nrow = 1)      
    

    enter image description here

提交回复
热议问题