chart_Series:如何格式化 x 轴以删除年份? [英] chart_Series: How to format the x axis to remove the year?

查看:54
本文介绍了chart_Series:如何格式化 x 轴以删除年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 x 轴中删除年份,使其仅显示日期和月份?另外,是否可以将 x 轴日期旋转 90 度?

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)

推荐答案

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:

You need to save the attributes so they can be put back in and you need to change the format.labels to your new specifications and then use the names from the axt vector rather than their value. The las parameter is the rotation indicator for base graphics. See ?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

这篇关于chart_Series:如何格式化 x 轴以删除年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆