繁体   English   中英

用 ggarrange 调整两个地块的高度(nrow=1)

[英]adjust heights of two plots (nrow=1) with ggarrange

如何使用 R function ggarrange() 在一行中显示两个图,以便它们具有相同的尺寸,特别是相同的高度?

在这个例子中,第二个 plot 比第一个 plot 高一点。 我想增加 a1_plot 的大小,使其与 a2_plot 的大小相匹配。

# required packages
library(ggplot2)
library(ggbreak)
library(directlabels)
library(ggpubr)

# make dataframe
df1 <- data.frame(first_column=c("value_1","value_2","value_3","value_4","value_4","value_5"),
                  second_column=c("123","123","325","325","656","656"),
                  third_column=c(12,13,1,19,200,360),
                  fourth_column=c(1,124,155,3533,5533,6666))

# plot 1
a1_plot <-
  ggplot(df1, aes(x=third_column, y=fourth_column, colour=second_column)) + 
  scale_x_continuous(breaks = c(0,50,100,150,200,250,300)) + 
  ylab("Fourth column")+ xlab("Third column") +
  scale_x_break(breaks = c(210,400)) +
  geom_dl(mapping=aes(x=third_column, y=fourth_column, label=second_column), 
          method = list(dl.trans(x = x + 0.1), dl.combine("last.points"))) + 
  theme(legend.position = "none") 

# plot 2
a2_plot <-
  ggplot(data=df1)+
  geom_point(aes(x=second_column, y=fourth_column) +
  xlab("X axis")+ ylab("Y axis") +
  theme(legend.position = "none")  

# merge plot1 and plot2
ggarrange(print(a1_plot), print(a2_plot), labels = c('a1', 'a2'))

我无法更改 plot 1 的高度。通过调整 plot 2 的边距,问题已解决。

theme(legend.position = "none", plot.margin = unit(x=c(3.6,5,3.9,0), units = "mm")) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM