仅在第一个轴壁虱或更改上展示年份
我有一个关于 R 中日期轴格式的问题。
我想在 x 轴上指定自定义日期刻度格式,如下所示: '%a %e %b \n %Y'
但我只想在第一个 x 轴刻度上显示年份。因为对每个刻度标签重复它太奇怪了。
我有以下小示例:
dt <- data.frame(
x = as.Date(c('2013-02-04', '2013-04-05', '2013-06-06', '2013-08-07', '2013-10-02')),
y = c(1,4,5,6,2)
)
plot_ly(data = dt, x = ~x, y = ~y, type = 'scatter', mode = 'lines') %>%
layout(xaxis = list(tickformat = '%a %e %b \n %Y'))
这与此 javascript 示例 它确实有效!
这篇使用 python 的文章似乎也有效。所以我现在不确定我在 R 中做错了什么?或者如果这是一个错误?
编辑:我想避免使用 ggplotly 并直接使用plotly,因为这提供了更好的控制。
I have a question regarding axis formatting of dates in R plotly.
I want to specify custom date tickformats on my x-axis as follows: '%a %e %b \n %Y'
But I only want to show the year on the first xaxis tick. As it would be too weird to repeat it for each tick label.
I have the following small example:
dt <- data.frame(
x = as.Date(c('2013-02-04', '2013-04-05', '2013-06-06', '2013-08-07', '2013-10-02')),
y = c(1,4,5,6,2)
)
plot_ly(data = dt, x = ~x, y = ~y, type = 'scatter', mode = 'lines') %>%
layout(xaxis = list(tickformat = '%a %e %b \n %Y'))
Which is the exact same setup from this javascript example where it does work!
This post with python also seems to work. So I am not sure now what I am doing wrong in R? Or if this is a bug?
Edit: I would like to avoid using ggplotly and directly work with plotly as this provide greater control.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论