-
Notifications
You must be signed in to change notification settings - Fork 167
Closed
Description
Hello,
I have encountered a problem with patchwork while collecting axis titles and guides together. I think this is the case when individual ggplots have multiple facets. What happens is that I can either collect the axis titles or the guides but not both. This could also happen when legend position is set to bottom. This code snippet should showcase the problem.
library(ggplot2)
library(patchwork)
#testdata
test1 = c(1, 2 ,3, 4)
test2 = c(4, 5, 6, 7)
type1 = c('A', 'A', 'B', 'B')
type2 = c('C', 'C', 'D', 'D')
df <- data.frame(test1, test2, type1, type2)
df$facet1 <- c('1', '1', '2', '2')
df$facet2 <- c('3', '3', '4', '4')
#plot1
p1 <- ggplot(df, aes(x = test1, y = test2, colour = type1)) +
theme_bw() +
geom_point() +
facet_wrap(~facet1) +
labs(x = 'numbers', y = 'also numbers', guide = 'letters') +
scale_colour_manual(values = c('red', 'green', 'blue'))
#plot2
p2 <- ggplot(df, aes(x = test1, y = test2, colour = type2)) +
theme_bw() +
geom_point() +
facet_wrap(~facet2) +
labs(x = 'numbers', y = 'also numbers', guide = 'letters') +
scale_colour_manual(values = c('yellow', 'pink', 'orange'))
#combine
p <- (p1 + p2 + plot_layout(axis_titles = 'collect', guides = 'collect') &
theme(legend.position = 'bottom'))
p
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
