【问题标题】:How to set xlim for time series in Plotly using R?如何使用 R 在 Plotly 中为时间序列设置 xlim?
【发布时间】:2018-06-27 19:35:30
【问题描述】:

这可能看起来类似于这个问题:How to format two Axes in Plotly using R? 但事实并非如此。加上这个没有任何回应。

我正在尝试使用 R 中的 Plot_ly 将三个子图(所有时间序列)放在另一个之下。虽然这些图是正确的,但我希望它们的 x 轴即日期时间范围相同。目前,第三个情节的时间戳从上午 8 点开始,而其他情节的时间戳从上午 00:00 开始。我希望我的第三个情节也从上午 00:00 开始,即使那里没有值。这将使视觉比较更容易。这是我的代码 sn-p:

pWrist <- plot_ly(combinedCounts, x = ~DATE_TIME, y= ~Vector.Magnitude_ANKLE, name = "ANKLE_COUNTS", legendgroup = "ANKLE", type = "bar")
pAnkle <- plot_ly(combinedCounts, x = ~DATE_TIME, y= ~Vector.Magnitude_WRIST, name = "WRIST_COUNTS", legendgroup = "WRIST", type = "bar")
pResponses <- plot_ly(uEMAResponsesOnly, x=~PROMPT_END_TIME, y=~RESPONSE_NUMERIC, name = "uEMA_RESPONSES", legendgroup = "uEMA", type = "bar")
subplot( style(pWrist, showlegend = TRUE), style(pAnkle, showlegend = TRUE), style(pResponses, showlegend = TRUE), nrows = 3, margin = 0.01)

subplot 函数将它们全部放在另一个之下。任何帮助或信息表示赞赏。

**编辑:**这是现在的样子。我只希望第三个轴也与前两个轴同时开始。如您所见,第三场比赛从早上 8 点开始。 Current plot

【问题讨论】:

  • 如果您提供a complete minimal reproducible example 来回答您的问题,我们更有可能为您提供帮助。我们可以从中工作并用来向您展示如何回答您的问题。
  • 我会简化我的问题。我只想更改 x 轴的日期时间范围。已添加示例图片以供参考。

标签: r plot plotly r-plotly


【解决方案1】:

解决了。

pResponses <- plot_ly(uEMAResponsesOnly, x=~PROMPT_END_TIME, y=~RESPONSE_NUMERIC, name = "uEMA_RESPONSES", legendgroup = "uEMA", type = "bar")%>% layout(xaxis = list(range = as.POSIXct(c('2018-01-13 00:00:00', '2018-01-14 23:00:00'))))

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 2020-11-25
    • 1970-01-01
    • 2020-01-23
    • 2015-02-10
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    相关资源
    最近更新 更多