Align violin plots with dodged box plots

前端 未结 1 1671
时光取名叫无心
时光取名叫无心 2020-12-14 02:01

I have this data frame

set.seed(1234)
x <- rnorm(80, 5, 1)
df <- data.frame(groups = c(rep("group1",20),
                           rep("         


        
1条回答
  •  囚心锁ツ
    2020-12-14 03:06

    You need to set the width of the dodging explicitly for both geoms:

    dodge <- position_dodge(width = 0.4)
    
    ggplot(data = df, aes(x = groups, y = value, fill = type)) +
      geom_violin(position = dodge)+
      geom_boxplot(width=.1, outlier.colour=NA, position = dodge) 
    

    enter image description here

    0 讨论(0)
提交回复
热议问题