Plot only one side/half of the violin plot

后端 未结 2 1053
说谎
说谎 2021-01-12 16:30

I would like to have only one half of violin plots (similar to the plots created by stat_density_ridges from ggridges). A MWE

library(ggplot2)

dframe = data         


        
2条回答
  •  半阙折子戏
    2021-01-12 16:43

    Package see has also a function geom_violinhalf that seems to do exactly what you want (see right plot below). It behaves mostly like geom_violin(), except does not have all arguments geom_violin() has (missing for example draw_quantiles)

    library(ggplot2)
    library(see)
    
    
    p <- ggplot(mtcars, aes(factor(cyl), mpg))
    p1 <- p + geom_violin()+ ggtitle("geom_violin")
    p2 <- p + see::geom_violinhalf()+ ggtitle("see::geom_violinhalf")
    
    ## show them next to each other
    library(patchwork)
    p1+p2
    

    Created on 2020-04-30 by the reprex package (v0.3.0)

提交回复
热议问题