簡體   English   中英

繪制XTS對象時的更改

[英]Changes in plotting an XTS object

我制作了下面的圖表,該圖表是使用xts對象創建的。

在此處輸入圖片說明

我使用的代碼很簡單

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

我更新了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”。 提前致謝。

您要刪除右手軸。 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)

做你想要的。

我試圖解決第二個問題,刪除了右上角的標簽。 檢查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")

第二個,也許更簡單的選擇是使用另一個繪圖函數,並對其進行修改以生成所需的網格線等。 我將從plot.zoo()開始,因為它已經很好地處理了時間序列。

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

至少可以將網格放置在那里。 我無法測試如果沒有正確頻率的數據,它是否會以相同的方式處理x軸標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM