问:在R中的单个图中显示分组和组合的箱形图 [英] Q: Display grouped and combined boxplot in a single plot in R

查看:99
本文介绍了问:在R中的单个图中显示分组和组合的箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将分组箱图和组合箱图显示为一个图。以 iris 数据为例:

I am trying to display grouped boxplot and combined boxplot into one plot. Take the iris data for instance:

data(iris)
p1 <- ggplot(iris, aes(x=Species, y=Sepal.Length)) + 
  geom_boxplot()
p1

我正在尝试将整体分布与每个类别中的分布进行比较。那么,有没有办法在这三个分组箱图的左侧显示所有样本的箱图?

I am trying to compare overall distribution with distributions within each categories. So is there a way to display a boxplot of all samples on the left of these three grouped boxplots?

预先感谢。

推荐答案

您可以 rbind 新版本的 iris ,其中种类等于所有行的全部 iris 在管道输送到 ggplot

You can rbind a new version of iris, where Species equals "All" for all rows, to iris before piping to ggplot

p1 <- iris %>% 
        rbind(iris %>% mutate(Species = 'All')) %>% 
        ggplot(aes(x = Species, y = Sepal.Length)) + 
          geom_boxplot()

这篇关于问:在R中的单个图中显示分组和组合的箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆