ggplot - 堆积条形图中的间隙

时间:2021-03-08 04:25:02

标签: r ggplot2 bar-chart

我有一些带有成绩单类别和计数的数据,我正在尝试创建一个堆积条形图,其中 ggplot 按类别填充。上一个/示例图显示了一个实心红色块,但是当我尝试使用我的数据时,我看到了很多白线。我认为它们可能是由于许多零计数造成的,但是在尝试了一些事情(包括将它们更改为 NA 并完全排除这些行)之后,该图仍然有这些白线。寻求一些澄清,谢谢!

数据子集(删除零计数的行):

isoform chrom strand length exons structural_category associated_transcript count
ENST00000627502.2     3      +    874     4   full-splice_match     ENST00000627502.2     2
ENST00000650569.1     1      -   6202    26   full-splice_match     ENST00000650569.1    51
ENST00000535093.1    18      +    582     6   full-splice_match     ENST00000535093.1    15
ENST00000338863.11     6      -   2983    13   full-splice_match    ENST00000338863.11     7
ENST00000570899.1    17      -    649     4   full-splice_match     ENST00000570899.1    24
ENST00000625998.2    13      -   5102    12   full-splice_match     ENST00000625998.2     7
ENST00000583693.5    17      +   3976     2   full-splice_match     ENST00000583693.5     9
ENST00000012134.7     6      -   9755     9   full-splice_match     ENST00000012134.7     4
ENST00000403263.5     2      -  14136    11   full-splice_match     ENST00000403263.5     1
ENST00000627368.2     5      -   1774    15   full-splice_match     ENST00000627368.2    14

Stacked bar plot

plot_isoformCount <- ggplot(isoClass_bambu, aes(x=method, y=count, fill=structural_category)) +
  geom_bar(position = position_stack(reverse = TRUE), stat = "identity") +
  labs(y = "Read count", x = "Method", fill = "Structural category") +
  theme_bw() +
  theme(text = element_text(size = 20), legend.position = "bottom") +
  scale_fill_manual(values = col.category) +
  scale_y_continuous(labels = unit_format(unit = "M", scale = 1e-6))
# dev.off()

leg <- get_legend(plot_isoformCount)

plot_grid(plot_isoformClass, plot_isoformCount + theme(legend.position = "none"), leg, rel_heights = c(1, 0.2))

0 个答案:

没有答案