如何使用r中的ggplot区分x轴上的样本

问题描述 投票:0回答:1

我使用ggplot创建了geom_bar图,该图沿x轴具有14个单独的样本。这些样本属于不同的组,我希望在图中添加一个元素,以指示哪些样本属于每个组。

例如,在此输出图中,样本HH11-HH21属于一个组,样本HH21-35属于另一组,其余部分属于另一组。For example in this output figure, samples HH11-HH21 belong to one group, HH21-35 belong to another and the remainder belong to another group

是否有可能在图的顶部添加彩色条,以指示样本所属的组?

这是我用来生成该图的代码:

ggplot(full_table_top30, aes(x = variable, y = value, fill = Genus)) +
  geom_bar(position = "fill", stat = "identity") +
  scale_fill_manual(breaks = Genus2, values = Cb64k) +
  scale_y_continuous(labels = percent_format()) +
  theme(legend.position = "right", text=element_text(size=12),
        axis.text.x = element_text(angle=90, vjust=1)) +
  guides(fill = guide_legend(ncol=2)) +
  ggtitle(opt$gtitle) +
  xlab("Patient ID") + ylab("Relative activity")
r ggplot2 graph figure geom-bar
1个回答
0
投票

我们没有您的数据,但我认为您正在寻找的是facet_grid()。如果我们建立一些数据:

© www.soinside.com 2019 - 2024. All rights reserved.