我创建了一个水平条形图,其中包含具有不同生物过程的条形图。这些进程根据其填充情况分配给一个 Group_ID。这些条已根据 Group_ID 排序。现在我希望在具有一个 Group_ID 的最后一个柱与下一个 Group_ID 的第一个柱之间有更大的空间。
我已经尝试过geom_bar(position =“dodge”)。我还尝试在 Group_ID 之后插入一个空栏。到目前为止一切都没有明显的变化
BP <- data.frame(
ID=c('Adaptive immune response', 'Immune response', 'Exocytosis', 'Peptide transport', 'Cell-cell adhesion', 'Lipid metabolism'),
Group_ID=c('Immune Response','Immune Response', 'Secretion And Transport', 'Secretion And Transport', 'Others', 'Others'),
log10=c(0.8, 0.2, 0.7, 0.9, 0.3, 0.5))
BP$Group_ID <- factor(BP$Group_ID, levels = c("Immune Response", "Secretion And Transport", "Others"))
BP <- BP[order(BP_Synu_PD$Group_ID, decreasing = TRUE),]
ggplot(BP, aes(x = factor(ID, levels = unique(ID)), y = log10, fill = Group_ID)) +
geom_bar(stat = "identity", position = "identity") +
coord_flip() +
scale_y_reverse() +
labs(title = "Bar Plot of signed log10(FDR)",
x = "ID",
y = "Signed log10(FDR)",
fill = "Group_ID") +
theme_few() +
theme(axis.text.y = element_text(size = 12),
legend.text = element_text(size = 15))
一种选择是使用分面,即通过
Group_ID
进行分面,然后使用 theme()
选项消除分面外观。此外,由于将在每个面周围绘制面板边框,因此我去掉了通过 theme()
绘制的面板边框,而是使用 geom_h/vline
来伪造面板边框:
library(ggplot2)
ggplot(BP, aes(
y = factor(ID, levels = unique(ID)),
x = log10, fill = Group_ID
)) +
geom_bar(stat = "identity", position = "identity") +
scale_x_reverse() +
scale_y_discrete(
expand = expansion(add = .6)
) +
facet_wrap(~Group_ID, ncol = 1, scales = "free_y") +
labs(
title = "Bar Plot of signed log10(FDR)",
y = "ID",
x = "Signed log10(FDR)",
fill = "Group_ID"
) +
geom_hline(
data = data.frame(
Group_ID = c("Immune Response", "Secretion And Transport"),
yintercept = c(Inf, -Inf)
),
aes(yintercept = yintercept)
) +
geom_vline(xintercept = c(-Inf, Inf)) +
ggthemes::theme_few() +
theme(
axis.text.x = element_text(size = 12),
legend.text = element_text(size = 15),
strip.text.x = element_blank(),
panel.border = element_rect(color = NA),
panel.spacing.y = unit(0, "pt")
)