Overlaying boxplot with histogram in ggplot2

后端 未结 3 557
花落未央
花落未央 2021-01-13 17:33

Hi I want to create a similar chart as shown below with R script:

taken from: https://community.tableau.com/thread/194440

this is my code in R :

3条回答
  •  粉色の甜心
    2021-01-13 18:13

    A good example where ggstance package comes in handy.

    library(ggplot2)
    library(ggstance)
    
    ggplot(iris, aes(x = Sepal.Length)) +
      geom_histogram() +
      geom_boxploth(aes(y = 3), width = 2, color = "blue", lwd = 2, alpha = .5) +
      theme_minimal() +
      facet_wrap(~Species, ncol = 1)
    

提交回复
热议问题