R / Shiny Plotly比例X轴日期绘图

时间:2017-08-03 16:14:14

标签: r shiny plotly

有人可以告诉我如何在按日期绘图时绘制比例x轴 - 参见附件吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用数字序列1,2,3,...直到nrow(df)作为x变量,并提供您自己的刻度线。例如:

df = data.frame(date=c("1 Aug","1 Aug","2 Aug","3 Aug"),value=c(1,1.2,2,4))

plot_ly(df, x =1:nrow(df),
        y =~value,type="scatter",
        mode="lines") %>%
  layout(xaxis=list(tickmode = 'array',
                    tickvals = 1:nrow(df),
                    ticktext = df$date,
                    range = c(0.5, nrow(df)+0.5)))

结果:

enter image description here

希望这有帮助!