如何从 x 轴中删除年份,使其仅显示日期和月份?另外,是否可以将 x 轴日期旋转 90 度?
library(quantmod)
getSymbols("SPY", from="2013-01-01", to=Sys.Date())
chart_Series(SPY,theme=myTheme)
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>
您需要保存属性以便将它们放回原处,并且需要将 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
您可以使用创建主题
myTheme <- chart_theme()
myTheme$format.labels <- '%b %d'
chart_Series(SPY,theme=myTheme)
那应该给你以下