ggplot2 violin plot: fill central 95% only?

后端 未结 3 1662
滥情空心
滥情空心 2020-12-19 05:57

ggplot2 can create a very attractive filled violin plot:

ggplot() + geom_violin(data=data.frame(x=1, y=rnorm(10 ^ 5)), 
    aes(x=x, y=y), fill=\'gray90\', c         


        
3条回答
  •  囚心锁ツ
    2020-12-19 06:29

    Just make a selection first. Proof of concept:

    df1 <- data.frame(x=1, y=rnorm(10 ^ 5))
    df2 <- subset(df1, y > quantile(df1$y, 0.025) & y < quantile(df1$y, 0.975))
    
    ggplot(mapping = aes(x = x, y = y)) + 
      geom_violin(data = df1, aes(fill = '100%'), color = NA) +
      geom_violin(data = df2, aes(fill = '95%'), color = 'black') +
      theme_classic() + 
      scale_fill_grey(name = 'level')
    

提交回复
热议问题