简体   繁体   English

不了解 R 中平均回报系列的十分位图

[英]Don't understand decile plotting of average return series in R

I am new to R and I am trying to plot a decile plot of annual average returns of the past 55 years.我是 R 的新手,我正在尝试 plot 过去 55 年的年平均回报率的十分位数 plot。 I have the portfolio return in average annual series of Decile 1 to Decile 10. What I want to do is to plot the decile series from 1 - 10 on the x-axis and on the y-axis the annualized average retur n.我的投资组合回报率在十等分 1 到十等分 10 的平均年度系列中。我想要做的是 plot 在 x 轴上从 1 到 10 的十分位系列,在 y 轴上是年化平均回报率 I have attached a picture of my data frame so you guys can see my point.我附上了我的数据框的图片,所以你们可以看到我的观点。 I hope somebody can help me on my way.我希望有人能在我的路上帮助我。 Thank you.谢谢你。

I have used this code here:我在这里使用了这段代码:

For ( i in seq(1,length( DATAFRAME ),1) ) plot(DATAFRAME[,i],ylab=names(DATAFRAME[i]),type="l")

It works, but I get all the graphs in 50 single plots, I want all the plots combined.它有效,但我在 50 个单图中获得了所有图表,我希望将所有图组合起来。 How can I combine all the plots based on the code above?如何根据上面的代码组合所有图?

This is the picture of the dataframe这是dataframe的图片

Using a small random example dataset this can be achieved like so:使用一个小的随机示例数据集,可以这样实现:

set.seed(42)

# example data
df <- data.frame(
  row.names = paste0("D", 1:10),
  X1 = runif(10),
  X2 = runif(10),
  X3 = runif(10),
  X4 = runif(10)
)
df
#>            X1        X2         X3          X4
#> D1  0.9148060 0.4577418 0.90403139 0.737595618
#> D2  0.9370754 0.7191123 0.13871017 0.811055141
#> D3  0.2861395 0.9346722 0.98889173 0.388108283
#> D4  0.8304476 0.2554288 0.94666823 0.685169729
#> D5  0.6417455 0.4622928 0.08243756 0.003948339
#> D6  0.5190959 0.9400145 0.51421178 0.832916080
#> D7  0.7365883 0.9782264 0.39020347 0.007334147
#> D8  0.1346666 0.1174874 0.90573813 0.207658973
#> D9  0.6569923 0.4749971 0.44696963 0.906601408
#> D10 0.7050648 0.5603327 0.83600426 0.611778643

# Plot layout: 2 rows, 2 columns
par(mfrow = c(2, 2))
for (i in seq_along(df)) {
  plot(df[, i], ylab = names(df[i]), type="l")
}

# Reset layout
par(mfrow = c(1, 1))

# All in one
cols <- seq(ncol(df))
matplot(as.matrix(df), type = c("b"), pch=1, col = cols) #plot
legend("topleft", legend = names(df), col = cols, pch=1) # optional legend

Created on 2020-04-25 by the reprex package (v0.3.0)代表 package (v0.3.0) 于 2020 年 4 月 25 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM