【发布时间】:2021-01-18 22:14:18
【问题描述】:
我想在一个地块上绘制 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)
【问题讨论】:
-
class(plot1)返回什么?如果它不包括ggplot,你是对的 - 它们不是 ggplots,grid.arrange将不起作用 -
它显示为
numeric。我想要做的就是将两个地块放入 1 个地块中。谢谢。