Reputation: 641
I am trying to move the y axis title towards the ticks. However, I'm having trouble doing this without cutting off the combmatrix labels. I've tried both with ggupset
and ggplot
functions. See reprex below.
Thank you for your help!
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)))
Created on 2021-07-30 by the reprex package (v2.0.0)
Upvotes: 2
Views: 397
Reputation: 15379
Like this?
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
BTW the same solution should work for ComplexUpset in principle.
Upvotes: 2
Reputation: 1599
This can be done in a tricky way.
The solution is to hide the y axis title and add text with annotate()
to the target position.
Since you did not provide your data, I will show it on an example.
Original plot:
ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))
Version with annotate
in place of the y-axis title:
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")
You just need to set the appropriate x
and y
coordinates and xlim
inside coord_cartesian
.
Upvotes: 0