0

我正在尝试将 y 轴标题移向刻度。但是,如果不切断组合矩阵标签,我会遇到麻烦。我已经尝试过 withggupsetggplot功能。请参阅下面的代表。

谢谢您的帮助!

library(dplyr)
library(ggupset)
library(ggplot2)

tidy_pathway_member <- 
  gene_pathway_membership %>%
  as_tibble(rownames = "Pathway") %>%
  tidyr::gather(Gene, Member, -Pathway) %>%
  filter(Member) %>%
  select(- Member)

g <-
  tidy_pathway_member %>%
  group_by(Gene) %>%
  summarize(Pathways = list(Pathway)) %>%
  ggplot(aes(x = Pathways)) +
  geom_bar() +
  scale_x_upset()

g

g +
  # Moves axis title towards ticks...but cuts off labels
  theme_combmatrix(combmatrix.label.make_space = FALSE)

g +
  # Also, moves axis title towards ticks...but cuts off labels
  theme(axis.title.y = element_text(margin = margin(r = -100)))

reprex 包于 2021-07-30 创建 (v2.0.0 )

4

2 回答 2

0

这可以通过一种棘手的方式来完成。

解决方法是隐藏 y 轴标题并将文本 with 添加annotate()到目标位置。

由于您没有提供您的数据,我将通过一个示例进行展示。

原图:

ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))

在此处输入图像描述

annotate代替 y 轴标题的版本:

ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) +
  theme(axis.title.y=element_blank()) + annotate(geom = "text", x = -0.2, y = 6500, label = "count", angle = 90, size=4) + 
  coord_cartesian(xlim = c(1, 8), clip = "off")

在此处输入图像描述

你只需要设置适当的xy坐标和xlim里面coord_cartesian

于 2021-07-30T21:12:56.810 回答
0

像这样?

library(dplyr)
library(ggupset)
library(ggplot2)

tidy_pathway_member <- 
  gene_pathway_membership %>%
  as_tibble(rownames = "Pathway") %>%
  tidyr::gather(Gene, Member, -Pathway) %>%
  filter(Member) %>%
  select(- Member)

g <-
  tidy_pathway_member %>%
  group_by(Gene) %>%
  summarize(Pathways = list(Pathway)) %>%
  ggplot(aes(x = Pathways)) +
  geom_bar() +
  scale_x_upset() +
  # the exact vjust number needed may vary depending on the plotting area size
  theme(axis.title.y = element_text(vjust=-30))

g

vjust=-30

顺便说一句,原则上相同的解决方案应该适用于 ComplexUpset。

于 2021-09-24T09:35:05.743 回答