I would like to be able to reduce the margins of the various plots but it seems that when I save the plot, the spaces between subplots don't get adjusted. It seems like the code I am using doesn't respond to plot.margin. I think it may be something to do with wrap and patchwork and/or the way I structured the themes, but I can't seem to figure it out. Any help will be greatly appreciated!
plot = ComplexUpset::upset(
data = Joint.all,
intersect = Workflows,
name = "",
width_ratio = 0.1,
wrap = FALSE,
set_sizes = (upset_set_size(geom = geom_bar(fill = "black"))+
scale_y_continuous(limits = c(0,NA),
expand = c(0.01,0),
breaks = c(0,1000,2000,3000),
labels = unit_format(unit = "K", scale = 1e-3, sep = ""))),
base_annotations = list(
'Intersection size (>1500)'= (
intersection_size(text = list(size = 1, color = "black", vjust = -4.4))+
scale_y_continuous(breaks = c(3000,3500),
labels = unit_format(unit = "K", scale = 1e-3, sep = ""),
expand = c(0.01,0))+
coord_cartesian(ylim = c(3000, 3600),
expand = TRUE)+
ylab('')),
'Intersection size'=(
intersection_size(text = list(size = 1., color = "black"))+
scale_y_continuous(breaks = c(0, 10, 20, 30, 40, 50),
expand = c(0.01,0))+
coord_cartesian(ylim = c(0, 50),
expand = TRUE))),
annotations = list(
"Patient" = (
ggplot(mapping = aes(fill = Patient))+
geom_bar(stat = "count", position = "fill")+
scale_y_continuous(labels = scales::percent_format())+
scale_fill_manual(values = c('1'='#006ba4',
'2'='#ff800e',
'3'='#ababab',
'4'='#595959',
'5'='#5f9ed1',
'6'='#898989',
'7'='#a2c8ec',
'8'='#c85200',
'9'='#ffbc79',
'10'='#cfcfcf'))+
ylab("Patient"))),
matrix = (
intersection_matrix(
geom = geom_point(
size = 0.2),
segment = geom_segment(
linewidth = 0.2))),
themes = upset_modify_themes(
list(
'intersections_matrix' = theme(
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_text(color = "black", size = 3, margin = margin(0,-2,0,0, "pt")),
panel.grid = element_blank(),
panel.background = element_blank(),
plot.background = element_blank(),
plot.margin = margin(0,0,0,0, "pt"),
title = element_blank()),
'Intersection size (>1500)' = theme(
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_blank(),
panel.grid = element_blank(),
axis.text.y = element_text(size = 4, color = "black", vjust = 0.5, margin = margin(0,1,0,0, "pt")),
axis.line.y = element_line(colour = "black", linewidth = 0.2344, lineend="round"),
axis.ticks.y = element_line(colour = "black", linewidth = 0.2344, lineend="round"),
axis.ticks.length.y = unit(1, "pt"),
legend.position = "none",
panel.background = element_blank(),
plot.background = element_blank(),
plot.margin = margin(b = -50),
title = element_blank()),
'Intersection size' = list(
theme_minimal(),
theme(
axis.text.x = element_blank(),
axis.title.x = element_blank(),
panel.grid = element_blank(),
axis.title.y = element_text(size = 4, color = "black", margin = margin(0,-8,0,5, "pt")),
axis.text.y = element_text(size = 4, color = "black", vjust = 0.5, margin = margin(0,1,0,0, "pt")),
axis.line = element_line(colour = "black", linewidth = 0.2344, lineend="round"),
axis.ticks.y = element_line(colour = "black", linewidth = 0.2344, lineend="round"),
axis.ticks.length.y = unit(1, "pt"),
legend.text = element_text(colour = "black",size = 4),
legend.justification = "top",
legend.position = "none",
legend.title = element_blank(),
legend.key.size = unit(6,"pt"),
legend.spacing.x = unit(1,"pt"),
legend.background = element_blank(),
legend.box.margin = margin(0,0,0,0, "pt"),
legend.margin = margin(0,0,0,0, "pt"),
panel.background = element_blank(),
panel.spacing.y = margin(0,0,0,0,"pt"),
plot.background = element_blank(),
plot.margin = margin(0,0,-50,0, "pt"),
title = element_blank())),
"Patient" = list(
theme_minimal(),
theme(
axis.text.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_text(size = 4, color = "black", margin = margin(0,-8,0,5, "pt")),
axis.text.y = element_text(size = 4, color = "black", vjust = 0.5, margin = margin(0,1,0,0, "pt")),
axis.line = element_line(colour = "black", linewidth = 0.2344, lineend="round"),
axis.ticks.y = element_line(colour = "black", linewidth = 0.2344, lineend="round"),
axis.ticks.length.y = unit(1, "pt"),
legend.text = element_text(colour = "black",size = 4),
legend.justification = "top",
legend.position = "none",
legend.title = element_blank(),
legend.key.size = unit(6,"pt"),
legend.spacing.x = unit(1,"pt"),
legend.background = element_blank(),
legend.box.margin = margin(0,0,0,0, "pt"),
legend.margin = margin(0,0,0,0, "pt"),
panel.grid = element_blank(),
panel.background = element_blank(),
panel.spacing.y = margin(0,0,-50,0,"pt"),
plot.background = element_blank(),
plot.margin = margin(0,0,-20,0, "pt"),
title = element_blank())),
"overall_sizes" = list(
theme_minimal(),
theme(
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.ticks.x = element_line(colour = "black", linewidth = 0.2344, lineend="round"),
axis.ticks.length.x = unit(1, "pt"),
axis.title.x = element_text(size = 4, color = "black", vjust = 0.5, margin = margin(-2,0,0,0, "pt")),
axis.text.x = element_text(size = 4, color = "black", vjust = 0.5, margin = margin(-1,0,0,0, "pt")),
panel.background = element_blank(),
panel.grid = element_blank(),
plot.margin = margin(r = 0))),
default = list(
theme_minimal(),
theme(
axis.text.x=element_blank(),
axis.title.x=element_blank())
))),
sort_intersections_by = "degree",
guides = "keep") +
patchwork::plot_layout(
heights = c(0.7, 0.3, 1, 0.7), nrow = 4)
plot
ggsave(plot = plot, file = "Figure_small.pdf", device = cairo_pdf, height = 2.7, width = 4, units = "in", dpi = 600,
path = panelspath)
ggsave(plot = plot, file = "Figure_big.pdf", device = cairo_pdf, height = 27, width = 40, units = "in", dpi = 600,
path = panelspath)
Hi!
Thanks for such a useful package!
I would like to be able to reduce the margins of the various plots but it seems that when I save the plot, the spaces between subplots don't get adjusted. It seems like the code I am using doesn't respond to
plot.margin. I think it may be something to do withwrapand patchwork and/or the way I structured the themes, but I can't seem to figure it out. Any help will be greatly appreciated!Below example of the same plot saved into two file sizes with
ggsave.Code:
Figure_big.pdf
Figure_small.pdf