如何从x轴中删除年份,使其仅显示日期和月份?此外,是否可以将x轴日期旋转90度?
library(quantmod)
getSymbols("SPY", from="2013-01-01", to=Sys.Date())
chart_Series(SPY,theme=myTheme)
Run Code Online (Sandbox Code Playgroud)
cspy <- chart_Series(SPY )
cspy$Env$actions[[3]]
#------------------
expression(axt <- axTicksByTime(xdata[xsubset], format.labels = format.labels),
axis(1, at = axt, labels = names(axt), las = 1, lwd.ticks = 1,
mgp = c(3, 1.5, 0), tcl = -0.4, cex.axis = 0.9))
attr(,"frame")
[1] 1
attr(,"clip")
[1] TRUE
attr(,"env")
<environment: 0x11cddc148>
Run Code Online (Sandbox Code Playgroud)
您需要保存属性以便可以将它们重新放入,并且需要将format.labels更改为新规范,然后使用axt向量中的名称而不是它们的值.该las参数是用于基础的图形旋转指示器.见?par:
attrs <- attributes(cspy$Env$actions[[3]])
cspy$Env$actions[[3]] <-
expression(axt <- axTicksByTime(xdata[xsubset], format.labels = "%b %d"),
axis(1, at = axt, labels = names(axt), las = 2, lwd.ticks = 1,
mgp = c(3, 1.5, 0), tcl = -0.4, cex.axis = 0.9))
attributes(cspy$Env$actions[[3]]) <- attrs
cspy
Run Code Online (Sandbox Code Playgroud)
