如何更改由svars软件包生成的ggplot图像中的构面标签 [英] How to change facet labels in ggplot image generated with the svars package

查看:53
本文介绍了如何更改由svars软件包生成的ggplot图像中的构面标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的该数据集的一个示例( data )来使用 svars

创建一个SVAR模型.

  data<-结构(c(-1.87308398729904,2.290631067509,0.993462708465565,-1.29041209029221、1.12545485962681,-2.636526517961、1.64791593479841,-0.127800586695059,-0.649131035554795,-1.41838122120497,-0.0727559182898574,2.61173864035165、0.408195006166245、2.14851460203356,-3.43206431417578,-3.21097438990066,-0.633222142832857、3.62032490350241,-1.88466472673507,3.1882672460176,-6.25889275693812,-5.63387155573629,-2.47686181080518,-0.00946230989793406,1.15917422619178,1.26429447879497、0.986332225049047,2.41168238340004,1.84115722165812,1.41639006961984,1.35342674612451,2.79543996486087、0.605266622518563、0.554959915380682、1.07421168196309,1.2403520539725、0.862800885835391、1.26464488451186、1.75852063191533,0.546966935763926、0.534163056633208、0.63109068920264、0.935286647736344,0.159975810472712、0.208743967794067、0.973862299523898)..Dim = c(23L,2L),. Dimnames = list(NULL,c("GDP","CPI")),index =结构(c(1420070400,1427846400、1435708800、1443657600、1451606400、1459468800、1467331200,1475280000、1483228800、1491004800、1498867200、1506816000、1514764800,1522540800、1530403200、1538352000、1546300800、1554076800、1561939200,1569888000、1577836800、1585699200、1593561600),tzone ="UTC",tclass =日期"),class = c("xts"),"zoo")) 

这是我使用的代码.我正在寻找更改构面标题的最简单方法,是否有一种方法可以在plot命令中传递新标题的向量.我知道通常你会通过 facet_wrap(〜.,labeller = as_labeller(c(`旧标题名称`=新标题名称"))当渲染标准ggplot时,我不确定如何在我的产品中复制它例子.

 #加载包pacman :: p_load(vars,svars,tidyverse)#创建VAR模型var.model<-vars :: VAR(data,p = 1,type ='both',season = NULL)#使用Cholesky分解的Crete SVAR模型svar.model<-id.chol(var.model)#引导和绘图核心<-parallel :: detectCores()-1boot.svar<-wild.boot(svar.model,design ="fixed",distr ="rademacher",nboot = 1000,n.ahead = 15nc =核心)情节(boot.svar) 

解决方案

如果我们查看

I'm using a sample of this dataset below (data) to create an SVAR model using the svars package

data <- structure(c(-1.87308398729904, 2.290631067509, 0.993462708465565, 
-1.29041209029221, 1.12545485962681, -2.636526517961, 1.64791593479841, 
-0.127800586695059, -0.649131035554795, -1.41838122120497, -0.0727559182898574, 
2.61173864035165, 0.408195006166245, 2.14851460203356, -3.43206431417578, 
-3.21097438990066, -0.633222142832857, 3.62032490350241, -1.88466472673507, 
3.1882672460176, -6.25889275693812, -5.63387155573629, -2.47686181080518, 
-0.00946230989793406, 1.15917422619178, 1.26429447879497, 0.986332225049047, 
2.41168238340004, 1.84115722165812, 1.41639006961984, 1.35342674612451, 
2.79543996486087, 0.605266622518563, 0.554959915380682, 1.07421168196309, 
1.2403520539725, 0.862800885835391, 1.26464488451186, 1.75852063191533, 
0.546966935763926, 0.534163056633208, 0.63109068920264, 0.935286647736344, 
0.159975810472712, 0.208743967794067, 0.973862299523898), .Dim = c(23L, 
2L), .Dimnames = list(NULL, c("GDP", "CPI")), index = structure(c(1420070400, 
1427846400, 1435708800, 1443657600, 1451606400, 1459468800, 1467331200, 
1475280000, 1483228800, 1491004800, 1498867200, 1506816000, 1514764800, 
1522540800, 1530403200, 1538352000, 1546300800, 1554076800, 1561939200, 
1569888000, 1577836800, 1585699200, 1593561600), tzone = "UTC", tclass = "Date"), class = c("xts", 
"zoo"))

Here is the code I've used. I'm looking for the easiest way to change the facet titles, is there a way to pass through a vector of new titles in the plot command. I know that typically you would pass facet_wrap(~.,labeller = as_labeller(c(`old title names` = "new title names") when rendering a standard ggplot, I'm just unsure of how I can replicate that in my example.


# Load Packages
pacman::p_load(vars, svars, tidyverse)

# Create VAR Model

var.model <- vars::VAR(data, p=1, type = 'both', season=NULL)

# Crete SVAR Model using Cholesky Decomposition

svar.model <- id.chol(var.model)

# Bootstrap and plot

cores <- parallel::detectCores() - 1

boot.svar <- wild.boot(svar.model, design = "fixed",
                            distr = "rademacher", nboot = 1000, n.ahead = 15,
                            nc = cores)

plot(boot.svar)

解决方案

If we review the source for the plot method for objects of class sboot, we'll see that the labels come from the column names of the data.frame in x$true[[1]].

So, it's kind of a hack, but very effective to just change the names:

colnames(boot.svar$true[[1]]) <- c("V1","A","B","C","D")
plot(boot.svar)

这篇关于如何更改由svars软件包生成的ggplot图像中的构面标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆