R中PerformanceAnalytics的并排图(Side by side plots for PerformanceAnalytics in R)

编程入门 行业动态 更新时间:2024-10-27 21:16:29
R中PerformanceAnalytics的并排图(Side by side plots for PerformanceAnalytics in R)

以下脚本并排绘制了2个图表:

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)

以下脚本无法并排绘制2个图表:

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个图表?

如果可能的话,我想避免使用另一个包。 谢谢。

The following script plots 2 charts side by side:

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)

The following script fails to plot 2 charts side by side:

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)

Would anyone know how to get the latter script to plot 2 charts side by side?

I would like to avoid using another package if possible. Thanks.

最满意答案

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

您可以这样做,并根据需要将其水平扩展到任意数量的符号(如果您愿意,可以超过2个符号) 在此处输入图像描述

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包(以及其他)的任何图表。

chart.PerformanceSummary is really just a wrapper to several charts.

You could do this, and extend it to any number of symbols horizontally if you wish (more than 2 symbols if you wanted)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", )

You need to add the appropriate parameters to each plot for things like colour and titles (leaving that to you), but you have the flexibility of adding any charts from the wonderful xts, quantmod, performanceAnalytics packages (and others).

更多推荐

本文发布于:2023-07-05 00:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Side   PerformanceAnalytics   plots   side

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!