绘制XTS对象时的更改

Mat*_*ham 2 plot r zoo xts

我制作了下面的图表,该图表是使用xts对象创建的。

在此处输入图片说明

我使用的代码很简单

   plot(graphTS1$CCLL, type = "l", las = 2, ylab = "(c)\nCC for Investors", xlab = "", main = "Clustering Coefficient at the Investor Level")
Run Code Online (Sandbox Code Playgroud)

我更新了R Studio软件包和R版本,然后通过运行相同的代码得到以下图表。

在此处输入图片说明

显然两者是不一样的。人们是否可以帮助我移除第二个Y轴-我不需要那个,并移除2007-03-01 / 2010-12-01的自动前进方向。许多尝试都失败了。我确实使用了zoo.plot,但是删除了网格线,能力和季度标记。

我的R版本是3.4.0(2017-04-21),具有以下平台“ x86_64-apple-darwin15.6.0”。提前致谢。

ati*_*too 5

您要删除右手轴。中有一个论点plot.xts(..., yaxis.right = TRUE, ...)。所以

library('xts')
#> Loading required package: zoo
#> 
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#> 
#>     as.Date, as.Date.numeric

data(sample_matrix)
sample.xts <- as.xts(sample_matrix, descr='my new xts object')

plot(sample.xts, yaxis.right = FALSE)
Run Code Online (Sandbox Code Playgroud)

做你想要的。

我试图解决第二个问题,删除了右上角的标签。检查的源代码可以plot.xts()发现标签已硬编码到主标题中。即使设置main = ''也不会删除它。您可以通过编辑plot.xts()并将其复制到新功能来解决该问题。

plotxts <- fix("plot.xts")
# In the editor that opens, replace the lines below:
###    text.exp <- c(expression(text(xlim[1], 0.5, main, font = 2, 
###        col = theme$labels, offset = 0, cex = 1.1, pos = 4)), 
###        expression(text(xlim[2], 0.5, paste(start(xdata[xsubset]), 
###            end(xdata[xsubset]), sep = " / "), col = theme$labels, 
###            adj = c(0, 0), pos = 2)))
###    cs$add(text.exp, env = cs$Env, expr = TRUE)
# with these lines:
###    text.exp <- expression(text(xlim[1], 0.5, main, font = 2,
###        col = theme$labels, offset = 0, cex = 1.1, pos = 4))

# Finally, you need to ensure your copy's environment is the xts namespace:
environment(plotxts) <- asNamespace("xts")

plotxts(sample.xts, yaxis.right = FALSE, main = "Main Title")
Run Code Online (Sandbox Code Playgroud)

第二个,也许更简单的选择是使用另一个绘图函数,并对其进行修改以生成所需的网格线等。首先,plot.zoo()因为它已经很好地处理了时间序列。

zoo::plot.zoo(sample.xts, screens = 1, xlab="", las=2, main="Main Title")
grid() # add the grid
Run Code Online (Sandbox Code Playgroud)

至少可以将网格放置在那里。我无法测试如果没有正确频率的数据,它是否会以相同的方式处理x轴标签。