组合多个绘图,使r中的宽度与ggplot相同

组合多个绘图,使r中的宽度与ggplot相同,r,ggplot2,patchwork,R,Ggplot2,Patchwork,就像标题一样,我想合并两个合并的绘图,但当我导出最终绘图时,它的宽度不同 我需要的是使每一个绘图都具有相同的宽度 为了明确这个问题,我做了一个假数据 library(patchwork) mpg <- mpg %>% mutate(class =paste0('This is a long long long name with ' ,class, sep = '')) d1 <- mpg %>% group_by(class,model) %>% summari

就像标题一样,我想合并两个合并的绘图,但当我导出最终绘图时,它的宽度不同

我需要的是使每一个绘图都具有相同的宽度

为了明确这个问题,我做了一个假数据

library(patchwork)
mpg <- mpg %>% mutate(class =paste0('This is a long long long name with ' ,class, sep = ''))

d1 <- mpg %>% group_by(class,model) %>% summarise(n = n())
d2 <- mpg %>% group_by(class,trans) %>% summarise(n = n())
d3 <- mpg %>% group_by(class,drv) %>% summarise(n = n())


p1 <- d1 %>% 
  ggplot(aes(x = class, y = n, fill = model)) +
  geom_col(position = 'fill', width = .6, 
           show.legend = T) + 
  coord_flip() +
  guides(fill = F)+
  theme_classic()

p2 <- d2 %>% 
  ggplot(aes(x = class, y = n , fill = trans)) +
  geom_col(position = 'fill', width = .6, 
           show.legend = T) + 
  guides(fill = F)+
  coord_flip() +
  theme_classic() +
  xlab(NULL)+
  ylab(NULL)+
  theme(axis.line.y = element_line(linetype = 1),
        axis.text.y = element_blank())

p3 <- d3 %>% 
  ggplot(aes(x = class, y = n, fill = drv)) +
  geom_col(position = 'fill', width = .6, 
           show.legend = T) + 
  guides(fill = F)+
  coord_flip() +
  theme_classic() +
  xlab(NULL)+
  ylab(NULL)+
  theme(axis.line.y = element_line(linetype = 1),
        axis.text.y = element_blank())

final <- p1|p2|p3

final2 <- final|final 

ggexport(final2, filename = 'test.pdf', width = 14, height = 8)


库(拼凑)
mpg%变异(class=paste0('这是一个长名称,带有',class,sep='')
d1%分组依据(类别、型号)%>%总结(n=n())
d2%分组依据(类别,事务)%>%汇总(n=n())
d3%分组依据(类别,drv)%>%总结(n=n())
p1%
ggplot(aes(x=类别,y=n,填充=模型))+
几何坐标(位置=‘填充’,宽度=.6,
show.legend=T)+
coord_flip()+
导轨(填充=F)+
主题(经典)
p2%
ggplot(aes(x=等级,y=n,填充=trans))+
几何坐标(位置=‘填充’,宽度=.6,
show.legend=T)+
导轨(填充=F)+
coord_flip()+
主题(经典)+
xlab(空)+
ylab(空)+
主题(轴线y=元素线(线型=1),
axis.text.y=元素_blank())
p3%
ggplot(aes(x=等级,y=n,填充=drv))+
几何坐标(位置=‘填充’,宽度=.6,
show.legend=T)+
导轨(填充=F)+
coord_flip()+
主题(经典)+
xlab(空)+
ylab(空)+
主题(轴线y=元素线(线型=1),
axis.text.y=元素_blank())

final通过以下方式定义final:
final