2017-07-14 107 views
3

PerformanceAnalytics下面的脚本图2图并排:并排地块为R中

require(xts) 
par(mfrow=c(1,2)) 
XTS1 <- structure(c(12, 7, 7, 22, 24, 30, 26, 23, 27, 30), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", class = c("xts", "zoo"), .CLASS = structure("double", class = "CLASS"), formattable = structure(list(formatter = "formatC", format = structure(list(format = "f", digits = 2), .Names = c("format", "digits")), preproc = "percent_preproc", postproc = "percent_postproc"), .Names = c("formatter", "format", "preproc", "postproc")), index = structure(c(1413981900, 1413982800, 1413983700, 1413984600, 1413985500, 1413986400, 1413987300, 1413988200, 1413989100, 1413990000), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(10L, 1L)) 
XTS2 <- XTS1^0.2 
plot(XTS1) 
plot(XTS2) 

下面的脚本未能并排绘制两个图表方:

require(PerformanceAnalytics) 
require(xts) 
par(mfrow=c(1,2)) 
XTS1 <- structure(c(12, 7, 7, 22, 24, 30, 26, 23, 27, 30), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", class = c("xts", "zoo"), .CLASS = structure("double", class = "CLASS"), formattable = structure(list(formatter = "formatC", format = structure(list(format = "f", digits = 2), .Names = c("format", "digits")), preproc = "percent_preproc", postproc = "percent_postproc"), .Names = c("formatter", "format", "preproc", "postproc")), index = structure(c(1413981900, 1413982800, 1413983700, 1413984600, 1413985500, 1413986400, 1413987300, 1413988200, 1413989100, 1413990000), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(10L, 1L)) 
XTS2 <- XTS1^0.2 
charts.PerformanceSummary(XTS1) 
charts.PerformanceSummary(XTS2) 

会有人知道如何让后面的脚本并排绘制2个图表?

如果可能,我想避免使用其他软件包。谢谢。

+2

看起来像'charts.PerformanceSummary'内部使用'layout'来设置它的三个图。我认为最好的选择是将两张图并排存入图中,然后将它们放在一起。 – Gregor

回答

3

chart.PerformanceSummary实际上只是几个图表的包装。

你可以做到这一点,如果你想(超过2个符号,如果你想)enter image description here它横向扩展到任何数量的符号:

par(mfrow=c(3,2)) 
# First row 
chart.CumReturns(XTS1, ylab = "Cumulative Return", main = "give me a title") 
chart.CumReturns(XTS2, ylab = "Cumulative Return", main = "give me a title2") 
# second row 
chart.BarVaR(XTS1) 
chart.BarVaR(XTS2) 

# third row 
chart.Drawdown(XTS1, main = "DD title", ylab = "Drawdown", 
) 
chart.Drawdown(XTS2, main = "", ylab = "Drawdown", 
) 

您需要将相应的参数添加到每个小区的比如颜色和标题(把它留给你),但是你可以灵活地添加美妙的xts,quantmod,performanceAnalytics包(和其他)的任何图表。