我想使用 rmarkdown 投影仪将以下四张图 (2 x 2) 放入单边。 我尝试了以下带有绘图选项的代码,包括 ggarrange() 和 plot_grid() 失败。 有什么想法吗?
{r fig.align="center", fig.cap= "\\label{fig:asset} Firms' performances between the chaebol-affliated and indpendent firms (non-chaebols)", warning=FALSE, echo=FALSE, message=FALSE}
par(mfrow=c(2,2))
library(cowplot)
library(ggplot2)
library(ggpubr)
library(tidyverse)
library(haven)
library(extrafont)
library(gridExtra)
df <- read_dta(file = "aaa.dta")
fchaebol = factor(df$chaebol)
p1 <- ggplot(df,aes(x= year, y= asset, color = fchaebol, linetype = fchaebol)) + theme_bw() +stat_summary(geom = "line", fun.y = mean)
p2 <-ggplot(df,aes(x= year, y= liability, color = fchaebol, linetype = fchaebol))+theme_bw() +stat_summary(geom = "line", fun.y = mean)
p3 <- ggplot(df,aes(x= year, y= sales, color = fchaebol, linetype = fchaebol))+theme_bw() +stat_summary(geom = "line", fun.y = mean)
p4 <- ggplot(df,aes(x= year, y= equity, color = fchaebol, linetype = fchaebol))+theme_bw() +stat_summary(geom = "line", fun.y = mean)
p1
p2
p3
p4
#ggarrange(p1, p2, p3, p4, ncol = 2, nrow = 2)
#plot_grid(p1,p2,p3,p4)
答案 0 :(得分:0)
尝试将 par(mfrow=c(2,2))
放在您的情节之前,如下所示:
par(mfrow=c(2,2))
p1
p2
p3
p4
这会将所有 4 个放置在同一个图中的 2x2 网格中。 c(2,2)
是绘图网格中的 c(rows,columns)。