将2个图组合成R中的1个图

Combining 2 plots into 1 plot in R

我想在一个地块上绘制 2 个地块。下面是创建绘图的代码。地块已创建,但我试图将它们放在同一个地块上。我不认为这些图是 [plots] 或 [ggplots] 类型。谢谢

library("fPortfolio")
library('fPortfolio')
data = SPISECTOR.RET
asset = dim(data)[2]

constraints <- c('minW[1:asset]=0','maxW[1:asset]=0.3')
spec <- portfolioSpec()
setNFrontierPoints(spec) <- 25
setSolver(spec)<- "solveRquadprog"

frontier <-portfolioFrontier(data, spec, constraints)

Pont <- 6

#I don't know if GGplot is needed
library(ggplot2)

#plot First Point [I don't think this is a ggplot]
plot1 <- weightsPie(object = frontier, pos = Pont, labels = F, col = rainbow(asset),
                    box = F, legend = F, radius = 0.8)

#plot Second Point [I don't think this is a ggplot]
plot2 <- weightsPie(object = frontier, pos = Pont, labels = T, col = rainbow(asset),
                    box = TRUE, legend = T, radius = 0)

#I want to Put the two plots on the same plot
library("gridExtra")
grid.arrange(plot1, plot2, nrow=1, ncol=2)

我知道 base R,但它至少显示了一些输出。 我用了layout来安排地块:

# your previous code

layout(matrix(c(1, 2), nrow = 1, byrow = TRUE))
layout.show(n=2)

plot1 <- weightsPie(object = frontier, pos = Pont, labels = F, col = rainbow(asset),
                    box = F, legend = F, radius = 0.8)

plot2 <- weightsPie(object = frontier, pos = Pont, labels = T, col = rainbow(asset),
                    box = TRUE, legend = T, radius = 0) 

此处输出:

"Arrangement"