2
votes

This may look similar to this question: How to format two Axes in Plotly using R? but it is not. Plus this one doesn't have any responses.

I am trying to have three subplots (all time-series) one under the other using Plot_ly in R. While the plots are correct, I want their x-axis i.e. date-time ranges to be same. At the moment the third plot has time stamp starting from 8 AM whereas others have it starting at 00:00 AM. I would like my third plot also to be starting at 00:00 AM even if there are no values there. This would make visual comparison much easier. Here is my code snippet:

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)

The subplot function puts them all one under the other. Any help or information is appreciated.

**EDIT: **Here is what it looks like right now. I just want the third axis also to start from the same time as the first two. As you can see, the third one starts at 8 AM. Current plot

1
It's more likely that we will be able to help you if you provide a complete minimal reproducible example to go along with your question. Something we can work from and use to show you how it might be possible to answer your question.Eric Fail
I will simplify my question. I just want to change the date time range for the x axis. Have added a sample image for reference.RforResearch

1 Answers

2
votes

This is solved.

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'))))