在绘图轴中显示我的数据框的日期列中包含的所有日期
Display all the dates that are in included in the date column of my dataframe in the plotly axis
我希望在我的折线图的 x 轴上显示我的数据集中包含的所有可能日期,而不是例如 Jan 2018
,然后是 Jul 2018
。
library(plotly)
date = c("2020-02-06", "2020-11-21", "2019-10-26",
"2020-09-20", "2020-01-11", "2019-09-15", "2020-08-03", "2019-02-05",
"2018-05-18", "2020-01-20", "2020-01-29", "2019-04-15", "2019-06-27",
"2017-11-29", "2017-12-01", "2019-04-04", "2017-11-28", "2018-11-29",
"2020-06-26", "2020-06-26")
traffic.sp = c("28", "28", "20",
"20", "22", "36", "36", "29", "0", "22", "23", "28", "28", "37",
"26", "15", "39", "38", "22", "22")
df<-data.frame(date,traffic.sp)
df$date<-as.Date(df$date, format = "%Y-%m-%d")
fig <- plot_ly(df, x = ~sort(date), y = ~traffic.sp, name = 'trace 0', type = 'scatter', mode = 'lines')
fig
忽略因包括所有可能的刻度而导致的不良格式,您可以在 layout()
中使用 tickvals
来操纵刻度出现在轴上的位置。
fig %>%
layout(xaxis = list(tickvals = unique(date)))
我希望在我的折线图的 x 轴上显示我的数据集中包含的所有可能日期,而不是例如 Jan 2018
,然后是 Jul 2018
。
library(plotly)
date = c("2020-02-06", "2020-11-21", "2019-10-26",
"2020-09-20", "2020-01-11", "2019-09-15", "2020-08-03", "2019-02-05",
"2018-05-18", "2020-01-20", "2020-01-29", "2019-04-15", "2019-06-27",
"2017-11-29", "2017-12-01", "2019-04-04", "2017-11-28", "2018-11-29",
"2020-06-26", "2020-06-26")
traffic.sp = c("28", "28", "20",
"20", "22", "36", "36", "29", "0", "22", "23", "28", "28", "37",
"26", "15", "39", "38", "22", "22")
df<-data.frame(date,traffic.sp)
df$date<-as.Date(df$date, format = "%Y-%m-%d")
fig <- plot_ly(df, x = ~sort(date), y = ~traffic.sp, name = 'trace 0', type = 'scatter', mode = 'lines')
fig
忽略因包括所有可能的刻度而导致的不良格式,您可以在 layout()
中使用 tickvals
来操纵刻度出现在轴上的位置。
fig %>%
layout(xaxis = list(tickvals = unique(date)))