带有堆叠列而不是分组的 R ggplot2

R ggplot2 with stacked column instead of grouped

我想将下面显示的数据绘制成一个分组 bar_plot。

我尝试了 position = "dodge"position = "dodge2" 但没有成功。我也试过 position = position_dodge()

如果我使用 geom_bar 而不是 geom_col 并删除 y=overlap_percent:

p3 <- ggplot(data = comp_coors, aes(x = species_code, fill = mirna_form)) + 
  geom_bar(position = "dodge2") + theme_classic()

p3

但我希望 y_axis 有 overlap_percent

另一个以堆叠条形图结束的尝试是:

p2 <- ggplot(data = comp_coors, aes(x = species_code, y = overlap_percent, fill = mirna_form)) + 
  geom_bar(stat = "identity") + theme_classic()

p2

最后通过使用 geom_col,它 returns 这没有意义,至少对我来说:

p4 <- ggplot(data = comp_coors, aes(x = species_code, y = overlap_percent, fill = mirna_form)) + 
  geom_col(position = "dodge") + theme_classic()

p4

我要绘制的数据:

comp_coors <- data.table( species = c("aae","cel", "dme","hsa", "mdo"),
mirna_form = c("mature", "precursor"),
overlap_percent = c(100.0, 100.0, 88.0, 95.5, 91.7, 100.0, 96.6, 98.4),
overlapping_attribute = c("ID=MIMAT0014285;Alias=MIMAT0014285", "ID=MI0000043;Alias=MI0000043;Name=cel-mir-72", "ID=MIMAT0000401;Alias=MIMAT0000401;Name=dme-miR-", "ID=MI0000791;Alias=MI0000791;Name=hsa-mir-383", "ID=MI0005331;Alias=MI0005331;Name=mdo-let-7g")
)

尝试使用 species 作为一个因素,然后像这样添加 stat = "identity"

ggplot(data = comp_coors, aes(x = factor(species), y = overlap_percent, fill = mirna_form)) + 
  geom_bar(position = "dodge", stat = "identity") + theme_classic() + labs(x = "Species", y = "Overlap percent")

输出:

y-axis 右侧 overlap_percent 的分组条形图。