控制哪些刻度线/标签在x轴上以绘图方式显示? [英] Control which tick marks / labels appear on x-axis in plotly?

查看:91
本文介绍了控制哪些刻度线/标签在x轴上以绘图方式显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想控制x轴上出现的刻度线.以下代码按5(在5、10、15 ... 30)的顺序放置刻度线

I want to have control over which tick marks appear on the x-axis. The following code places tick marks in a sequence of 5 (at 5, 10, 15 ... 30)

library(plotly)

df <- data.frame(x =  1:30,
                 y = sample(100:300, size = 30, replace = T))

p <- plot_ly(data = df, x = x, y = y, type = 'line') %>%
      layout(title = 'Example plot')
p

我需要按6、12、18、24、30的顺序放置它们.我一直在浏览文档,但似乎找不到我需要的东西.在ggplot2中,这可以通过scale_x_continuous(breaks=c(6,12,18,24,30)完成.

I need to place them in a sequence of 6 at 6, 12, 18, 24, 30. I've been browsing the documentation but I cannot seem to find what I need. In ggplot2 this can be done via scale_x_continuous(breaks=c(6,12,18,24,30).

推荐答案

您可以使用style添加对勾:

p <- plot_ly(data = df, x = x, y = y, type = 'line') %>%
    layout(title = 'Example plot', xaxis = list(autotick = F, dtick = 6))
p

还有更多示例: https://plot.ly/r/axes/

这篇关于控制哪些刻度线/标签在x轴上以绘图方式显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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