ggplot dotplot: What is the proper use of geom_dotplot?

后端 未结 3 1434
小鲜肉
小鲜肉 2021-02-20 13:51

My purpose is to reproduce this figure [ref] with ggplot2 (author: Hadley Wickham).

Here is my effort based on geom_point and some ugl

3条回答
  •  后悔当初
    2021-02-20 14:32

    Is this close enough for the reproduction?

    To get there, since the first plot is really a histogram, expand your example data back out into one row per observation form, from the count summaries.

    df <- tidyr::uncount(df, y)  
    

    Then using method = 'histodot' and bindwidth=1 to get geom_dotplot() into it's histogram-y form.

    And removing the y-axis for aesthetic, because it's fractional gibberish and even the docs say it "isn't really meaningful, so hide it".

    ggplot(df, aes(x)) +
      geom_dotplot(method = 'histodot', binwidth = 1) +
      scale_y_continuous(NULL, breaks = NULL)
    

提交回复
热议问题