1

How can I remove the Year from the x axis so that it only shows the day and month? Also, is it possible to rotate the x axis dates by 90 degrees?

library(quantmod)
getSymbols("SPY", from="2013-01-01", to=Sys.Date())
chart_Series(SPY,theme=myTheme)
4

2 に答える 2

6
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

ここに画像の説明を入力

于 2013-10-05T18:22:38.447 に答える