R graphs: Creating Tufte's horizontal bar lines

前端 未结 3 671
礼貌的吻别
礼貌的吻别 2020-12-14 02:39

How can we replicate Tufte\'s implicit horizontal lines in R?

\"Tufte

For example, the following

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 03:25

    In principle, this is straightforward - all you need to do is draw white horizontal lines in a new layer. You can use geom_hline to do this:

    library(ggplot2)    
    ggplot(msleep, aes(x=order)) + stat_bin() + theme_bw() +
      geom_hline(yintercept=seq(5, 20, 5), col="white")
    

    enter image description here

    As for your second question - I'd imagine this may be hard to incorporate in a theme, although it should be possible to create a custom geom that reads the y-scale breaks and plot the lines correspondingly.

    (I'd love to be proved wrong.)

提交回复
热议问题